Sabtu, 05 Mei 2012

Pin It

Program List Implicit pada J2ME

Diposting oleh fitri apriani di Sabtu, Mei 05, 2012

Selamat malam all readers, malam minnggu gini gak ada kerjaan kita ngepost aja deh tugas buat hari senin nanti. Posting ini adalah tugas "Komputasi Nirkabel" tentang ListImplicit dengan textbox. Oke langsung aja check it these coding belows ;)
 

importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
public class textbox extends MIDlet implements CommandListener {
Display display;
List list;
TextBox textbox;
Command exitCommand = new Command("Exit", Command.EXIT, 1);
Command addCommand = new Command("Add Item", Command.OK, 1);
Command removeCommand = new Command("Remove Item", Command.OK, 1);
Command okCommand = new Command("OK", Command.OK, 1);
Command cancelCommand = new Command("Cancel", Command.EXIT, 1);
publictexbox(){
list = new List("Komputasinirkabel", List.IMPLICIT);
list.addCommand(exitCommand);
list.addCommand(addCommand);
list.addCommand(removeCommand);
list.setCommandListener(this);
textbox = new TextBox("Add List Item", "", 64, TextField.ANY);
textbox.addCommand(okCommand);
textbox.addCommand(cancelCommand);
textbox.setCommandListener(this);
}
public void startApp() {
if (display == null){
display = Display.getDisplay(this);
display.setCurrent(list);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d){
if (c == exitCommand){
notifyDestroyed(); // Exit
}
if (c == addCommand){
textbox.setString("");
display.setCurrent(textbox);
}
if (c == removeCommand){
int index = list.getSelectedIndex();
if (index != -1){

list.delete(index);
} else {
// no item selected
}
}
if (c == okCommand){
int index = list.getSelectedIndex();
if (index != -1){
list.insert(index, textbox.getString(), null);
} else {
// list might be empty
list.append(textbox.getString(), null);
}
display.setCurrent(list);
}
if (c == cancelCommand){
display.setCurrent(list);
}
}’
}

Nah, untuk coding diatas, kamu bisa ganti nama classnya sesuai yang ingin kamu buat.. Selamat mencoba dan jangan lupa tinggalkan jejak komentar dibawah ya :)

0 komentar:

Posting Komentar

 

MARI BELAJAR :) Template by Ipietoon Blogger Template | Gift Idea