Mega Code Archive

 
Categories / Java Tutorial / J2ME
 

Use ChoiceGroup

import java.io.IOException; import javax.microedition.lcdui.ChoiceGroup; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.midlet.MIDlet; public class ChoiceGroupMIDlet extends MIDlet {   protected Display display;   protected void startApp() {     display = Display.getDisplay(this);     Form form = new Form("Demo");     form.append("line");         try {           Image red = Image.createImage("/red.png");           Image green = Image.createImage("/green.png");           Image blue = Image.createImage("/blue.png");                String[] strings = new String[] { "Red", "Green", "Blue" };           Image[] images = new Image[] { red, green, blue };           ChoiceGroup exGroup = new ChoiceGroup("Choose one", ChoiceGroup.EXCLUSIVE,                                                       strings, images);           form.append(exGroup);           ChoiceGroup multiGroup = new ChoiceGroup("Choose any", ChoiceGroup.MULTIPLE);           form.append(multiGroup);           multiGroup.append("Use SSL", null);           multiGroup.append("Reconnect on failure", null);           multiGroup.append("Enable tracing", null);        } catch (IOException ex) {           form.append("Failed to load images");        }     display.setCurrent(form);   }   protected void pauseApp() {   }   protected void destroyApp(boolean unconditional) {   } }