/* Create a Multiple choice application, save selection status of each element in an array*/ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class MultChoice extends MIDlet implements CommandListener { // Reference to application objects private Display display; private Command cmExit; private Command cmView; private List lsChoice; int i; // Constructor public MultChoice(){ display = Display.getDisplay(this); // MultipleChoice list lsChoice = new List("Maintenance List:", List.MULTIPLE); // Append Options with no asociated images lsChoice.append("Security Sensors", null); lsChoice.append("Light Bulbs", null); lsChoice.append("Locks", null); lsChoice.append("Key Pad", null); cmExit = new Command("Exit", Command.EXIT, 1); cmView = new Command("View", Command.SCREEN, 1); // add commands lsChoice.addCommand(cmExit); lsChoice.addCommand(cmView); // listen for events lsChoice.setCommandListener(this); } // startApp public void startApp(){ display.setCurrent(lsChoice); } // pauseApp public void pauseApp(){ } // destroyApp public void destroyApp(boolean unconditional){ } public void commandAction(Command c, Displayable s){ // check if View command is triggered craete a boolean array to check // the selected elements if (c == cmView){ boolean selected[] = new boolean [lsChoice.size()]; // fill array indicating if each element is selected lsChoice.getSelectedFlags(selected); for (int i = 0; i < lsChoice.size(); i++) System.out.println(lsChoice.getString(i) + (selected[i] ? ": Order" : ": Not Order")); } else if (c == cmExit){ destroyApp(false); notifyDestroyed(); } } }