ChoiceGroup With Image


<strong>/*————————————————–</strong>
<strong>* ChoiceGroupWithImages.java</strong>
<strong>*</strong>
<strong>* Example from the book: Core J2ME Technology</strong>
<strong>* Copyright John W. Muchow http://www.CoreJ2ME.com</strong&gt;
<strong>* You may use/modify for any non-commercial purpose</strong>
<strong>*————————————————-*/</strong>
<strong>import javax.microedition.midlet.*;</strong>
<strong>import javax.microedition.lcdui.*;</strong>

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

<strong>public ChoiceGroupWithImages()</strong>
<strong> {</strong>
<strong> display = Display.getDisplay(this);</strong>

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

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

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

<strong>}</strong>
<strong> catch (java.io.IOException e)</strong>
<strong> {</strong>
<strong> System.err.println(”Unable to locate or read .png file”);</strong>
<strong> }</strong>

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

<strong>// Create Form, add components, listen for events</strong>
<strong> fmMain = new Form(””);</strong>
<strong> fmMain.append(cgPrefs);</strong>
<strong> fmMain.addCommand(cmExit);</strong>
<strong> fmMain.addCommand(cmView);</strong>
<strong> fmMain.setCommandListener(this); </strong>
<strong> }</strong>

<strong>public void startApp()</strong>
<strong> {</strong>
<strong> display.setCurrent(fmMain);</strong>
<strong> }</strong>

<strong>public void pauseApp()</strong>
<strong> { }</strong>

<strong>public void destroyApp(boolean unconditional)</strong>
<strong> { }</strong>

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

<strong>// Fill array indicating whether each element is checked </strong>
<strong> cgPrefs.getSelectedFlags(selected);</strong>

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

Tinggalkan Balasan

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

Logo WordPress.com

You are commenting using your WordPress.com 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

Mari kita bersama meningkatkan kesadaran kita - Mulailah berpikir cerdas, Kita semua beragama !!! Agama bukan identitas...jadikanlah agama untuk keluar dari kebodohan

Tulisan di blog ini mungkin sangat ngawur tapi mungkin juga benar. Merdekakan pikiran anda, sentuh hati nurani anda. Yang ada tinggal KASUNYATAN SEJATI

Zoemalang's community at www. zoemalang.wordpress.com

ujung malang adalah Sebuah desa yang hilang terganti dengan ujung harapan

YoYo Games Blog Feed

Tulisan di blog ini mungkin sangat ngawur tapi mungkin juga benar. Merdekakan pikiran anda, sentuh hati nurani anda. Yang ada tinggal KASUNYATAN SEJATI

Dealer Termurah

Menjual Segala Jenis Motor Baru Di Indonesia Cash Maupun Kredit

%d blogger menyukai ini: