ChoiceGroup With Image

* Example from the book: Core J2ME Technology
* Copyright John W. Muchow
* You may use/modify for any non-commercial purpose
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ChoiceGroupWithImages extends MIDlet implements CommandListener
private Display display; // Reference to display object
private Form fmMain; // Main form
private Command cmExit; // Command to exit the MIDlet
private Command cmView; // View the choice selected
private ChoiceGroup cgPrefs; // Choice Group of preferences

public ChoiceGroupWithImages()
display = Display.getDisplay(this);

// Create array of image objects
Image images[] = {Image.createImage(”/up.png”), Image.createImage(”/down.png”),
Image.createImage(”/help.png”) };

// Create array of corresponding string objects
String options[] = {”Upload”, “Download”, “Help”};

// Create a choice group using arrays
cgPrefs = new ChoiceGroup(”Select Option:”, Choice.EXCLUSIVE, options, images);

catch ( e)
System.err.println(”Unable to locate or read .png file”);

cmExit = new Command(”Exit”, Command.EXIT, 1);
cmView = new Command(”View”, Command.SCREEN,2);

// Create Form, add components, listen for events
fmMain = new Form(””);

public void startApp()

public void pauseApp()
{ }

public void destroyApp(boolean unconditional)
{ }

public void commandAction(Command c, Displayable s)
if (c == cmView)
boolean selected[] = new boolean[cgPrefs.size()];

// Fill array indicating whether each element is checked

// Print to console the status of each element
for (int i = 0; i < cgPrefs.size(); i++)
System.out.println(cgPrefs.getString(i) + (selected[i] ? “: selected” : “: not selected”));
else if (c == cmExit)

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Zoemalang's community

ujung malang adalah Sebuah desa yang hilang terganti dengan ujung harapan

YoYo Games Blog Feed

Ujung malang adalah Sebuah desa yang hilang terganti dengan ujung harapan

Dealer Termurah

Menjual Segala Jenis Motor Baru Di Indonesia Cash Maupun Kredit

%d blogger menyukai ini: