Assignment 9-4 // 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{ /************************************************************************ Declare private classes for display, a Form, Exit and View Commands and A ChoiceGroup ***************************************************************************/ // contructor public ChoiceGrImages(){ /*********************************************************************** get the display for this midlet create the command objects add the commands append the choiceGroup item to the form setCommandListener to this midlet **********************************************************************/ // try and catch exceptions whilst creating image items 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 } /****************************************************** startApp( ) set the Form as current display ******************************************************/ /************************************************** pauseApp( ) *****************************************************/ /************************************************* DestroyApp( ) ************************************************/ // 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