import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MultipleList extends MIDlet
implements CommandListener {
private Display display;
private List list;
private Command cmdPilih;
private Command cmdKembali;
public ExclusiveList() {
display = Display.getDisplay(this);
}
public void startApp() {
// membuat daftar command yang akan digunakan
cmdPilih = new Command("Pilih", Command.SCREEN, 2);
cmdKembali = new Command("Kembali", Command.EXIT, 1);
// membuat gambar icon untuk setiap item List
Image img;
try {
img = Image.createImage("/app.png");
} catch (Exception e) {
img = null;
}
// membuat List dengan tipe IMPLICIT
list = new List("Tipe MULTIPLE", Choice.MULTIPLE);
list.append("Pilihan pertama", img);
list.append("Pilihan kedua", img);
list.append("Pilihan ketiga", img);
list.append("Pilihan keempat", img);
list.addCommand(cmdPilih);
list.addCommand(cmdKembali);
list.setCommandListener(this);
display.setCurrent(list);
}
public void pauseApp() {
//
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKembali) {
destroyApp(false);
} else {
boolean[] pilihan = new boolean[list.size()];
list.getSelectedFlags(pilihan);
String str = "";
for (int i=0; i < pilihan.length; i++) {
if (pilihan[i] == true) {
str = str + list.getString(i) + '\n';
/* keterangan: '\n' = new line */
}
}
Alert info = new Alert("Informasi");
info.setString(str);
info.setTimeout(Alert.FOREVER);
display.setCurrent(info, list);
}
}
}
No comments:
Post a Comment