// This midlet shows a choice group with associated strings and images import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.io.IOException; public class ChoiceGrImages extends MIDlet implements CommandListener{ private Display display; // a display private Form fmMain; // a form private Command cmExit; // exit command private Command cmView; // view command private ChoiceGroup cgPref; // choice group of preferences // contructor public ChoiceGrImages(){ display = Display.getDisplay(this); // add commands cmExit = new Command("Exit", Command.EXIT, 1); cmView = new Command("cmView", Command.SCREEN, 2); try{ // create an array of image objects Image img[] = {Image.createImage("/res/redcircle.png"), Image.createImage( "/res/greencircle.png"), Image.createImage("/res/bluecircle.png")}; // Create string object to associate with the images String opt[] = {"Red Circle", "Green Circle", "Blue Circle"}; // Create choice group using array cgPref = new ChoiceGroup("Select Color:", Choice.EXCLUSIVE, opt, img); } catch (java.io.IOException e){ System.err.println("Unable to locate or read .png file"); } // create form, add components, listen for events fmMain = new Form(" "); fmMain.addCommand(cmExit); fmMain.addCommand(cmView); fmMain.append(cgPref); fmMain.setCommandListener(this); } // start app public void startApp(){ display.setCurrent(fmMain); } // pause app public void pauseApp(){ } // destroy app public void destroyApp(boolean unconditional){ } // commandAction public void commandAction(Command c, Displayable s){ if(c == cmView){ boolean selected[] = new boolean[cgPref.size()]; // Fill array showing if any item has been checked cgPref.getSelectedFlags(selected); // print to console the status of each element for(int i = 0; i