Subscribe to RSS Feed

Jumat, 08 Juni 2012

Tulisan 13: Contoh Program Choice Group J2ME

mport javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class cthChoiceGroup extends MIDlet implements CommandListener
{

private Display display;
private List list;
private Form form;
private ChoiceGroup menu;

private String[] daftarMenu = {
"Pilihan Pertama",
"Pilihan Kedua",
"Pilihan Ketiga",
"Pilihan Keempat",
};

private final Command cmdKeluar= new Command ("Keluar", Command.EXIT,1);
private final Command cmdOK= new Command ("OK", Command.OK,1);
private final Command cmdKembali= new Command ("Kelmbali", Command.BACK,1);

public cthChoiceGroup() {
display = Display.getDisplay(this);
form = new Form("Contoh ChoiceGroup");
form.addCommand(cmdKembali);
form.setCommandListener(this);
}

public void startApp() {
list = new List("Contoh ChoiceGroup", Choice.IMPLICIT);
list.append("Tipe EXCLUSIVE", null);
list.append("Tipe MULTIPLE", null);
list.append("Tipe POPUP", null);
list.addCommand(cmdKeluar);
list.addCommand(cmdOK);
list.setCommandListener(this);

display.setCurrent(list);
}

public void pauseApp(){}

public void destroyApp(boolean unconditional){}

public void commandAction (Command c, Displayable s){
if (c==cmdKeluar){
destroyApp(false);
notifyDestroyed();
} else if (c==cmdKembali){
display.setCurrent(list);
} else {
menu = null;
switch (list.getSelectedIndex()) {
case 0 : {
menu = new ChoiceGroup("Tipe EXCLUSIVE", Choice.EXCLUSIVE, daftarMenu, null);
break;
}
case 1 : {
menu = new ChoiceGroup("Tipe MULTIPLE", Choice.MULTIPLE, daftarMenu, null);
break;
}
case 2 : {
menu = new ChoiceGroup("Tipe POPUP", Choice.POPUP, daftarMenu, null);
break;
}
}
form.deleteAll();
form.append(menu);
display.setCurrent(form);
}
}
}

0 komentar:

Posting Komentar