001: /*
002: *
003: * Copyright (c) 2007, Sun Microsystems, Inc.
004: *
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * * Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * * Neither the name of Sun Microsystems nor the names of its contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032: package choicegroup;
033:
034: import javax.microedition.lcdui.*;
035: import javax.microedition.midlet.MIDlet;
036:
037: /**
038: * The alert demo displays a list of alerts that will be displayed once the
039: * user clicks a list item. These alerts try to present the full range of
040: * alert types supported in MIDP.
041: *
042: * @version 2.0
043: */
044: public class ChoiceGroupDemo extends MIDlet implements CommandListener {
045: private static final Command CMD_EXIT = new Command("Exit",
046: Command.EXIT, 1);
047: private Display display;
048: private boolean firsttime;
049: private Form mainForm;
050:
051: public ChoiceGroupDemo() {
052: firsttime = true;
053: }
054:
055: protected void startApp() {
056: if (firsttime) {
057: display = Display.getDisplay(this );
058:
059: mainForm = new Form("Choice Group");
060: mainForm
061: .append("These are the available choice group types");
062:
063: // these are the images and strings for the choices.
064: Image[] imageArray = null;
065:
066: try {
067: // load the duke image to place in the image array
068: Image duke = Image.createImage("/midp/uidemo/Icon.png");
069:
070: // these are the images and strings for the choices.
071: imageArray = new Image[] { duke, duke, duke, duke };
072: } catch (java.io.IOException err) {
073: // ignore the image loading failure the application can recover.
074: }
075:
076: String[] stringArray = { "Option A", "Option B",
077: "Option C", "Option D" };
078:
079: // create the list of choice groups.
080: ChoiceGroup[] groups = {
081: new ChoiceGroup("Exclusive", ChoiceGroup.EXCLUSIVE,
082: stringArray, imageArray),
083: new ChoiceGroup("Multiple", ChoiceGroup.MULTIPLE,
084: stringArray, imageArray),
085: new ChoiceGroup("Pop-Up", ChoiceGroup.POPUP,
086: stringArray, imageArray) };
087:
088: for (int iter = 0; iter < groups.length; iter++) {
089: mainForm.append(groups[iter]);
090: }
091:
092: mainForm.addCommand(CMD_EXIT);
093: mainForm.setCommandListener(this );
094: firsttime = false;
095: }
096:
097: display.setCurrent(mainForm);
098: }
099:
100: public void commandAction(Command c, Displayable d) {
101: if (c == CMD_EXIT) {
102: destroyApp(false);
103: notifyDestroyed();
104: }
105: }
106:
107: protected void destroyApp(boolean unconditional) {
108: }
109:
110: protected void pauseApp() {
111: }
112: }
|