/* In this example we will construct a choice group using the Append()method. We design an exclusive choice, where only one element can be chosen at a time */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ExChGr extends MIDlet implements CommandListener{ private Display display; // a display private Form fmMain; // form private Command cmExit; // Exit command private Command cmView; // View the choice selected private ChoiceGroup cgSMS; // Choice group private int replyIndex; // "reply" index in the choice group private int choiceGroupIndex; // Index of choice group on the form // constructor public ExChGr(){ display = Display.getDisplay(this); // Create an Exculsive Radio group cgSMS = new ChoiceGroup("SMS Options", Choice.EXCLUSIVE); // Append options with images associated cgSMS.append("Read", null); // make note of the inex of the "Reply" entry replyIndex = cgSMS.append("Reply", null); cgSMS.append("Forward", null); cgSMS.append("Delete", null); // Set "reply" as the defualt selected option cgSMS.setSelectedIndex(replyIndex, true); // add commands cmExit = new Command("Exit", Command.EXIT, 1); cmView = new Command("View", Command.SCREEN, 2); // create form, add components, listen for events fmMain = new Form("You have new message ..."); choiceGroupIndex = fmMain.append(cgSMS); fmMain.addCommand(cmExit); fmMain.addCommand(cmExit); fmMain.addCommand(cmView); fmMain.setCommandListener(this); } // start App public void startApp(){ display.setCurrent(fmMain); } public void pauseApp(){ //pause app } public void destroyApp(boolean unconditional){ // destroy App } // Command Action public void commandAction(Command c, Displayable s){ if(c == cmView){ // build a string showing which option was slected StringItem siMessage = new StringItem("You Selected: ", cgSMS.getString (cgSMS.getSelectedIndex())); // show the string siMessage fmMain.append(siMessage); // delete the choice group and view button fmMain.removeCommand(cmView); fmMain.delete(choiceGroupIndex); } else if (c == cmExit){ destroyApp(false); notifyDestroyed(); } } }