Command memiliki 3 atribut, yaitu :
- label : menampilkan nama pada tombol Command
- type : menentukan fungsi dari Command. Jenis type Command antara lain BACK, EXIT, OK, HELP, CANCEL, SCREEN, ITEM, dan STOP.
- priority : menentukan urutan prioritas dalam menampilkan Command pada layar
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* @author programmer dekil
*/
public class Midlet extends MIDlet implements CommandListener{
private Display layar;
private TextField tfNim;
private TextField tfNama;
private Form form;
private Command cmdKeluar;
private Command cmdOK;
private StringItem str;
public Midlet(){
form = new Form("Data Mahasiswa");
tfNim = new TextField("NIM", null, 6, TextField.NUMERIC);
tfNama = new TextField("Nama", null, 30, TextField.ANY);
cmdOK = new Command("OK", Command.OK, 0);
cmdKeluar = new Command("Keluar", Command.EXIT, 0);
form.append(tfNim);
form.append(tfNama);
form.addCommand(cmdOK);
form.addCommand(cmdKeluar);
}
public void commandAction(Command c, Displayable d) {
if (c == cmdKeluar){
destroyApp(true);
}else if (c == cmdOK){
str = new StringItem(null, "Data Mahasiswa :\nNIM : "
+ tfNim.getString() + "\nNama : " +
tfNama.getString());
form.append(str);
}
}
public void startApp() {
layar = Display.getDisplay(this);
layar.setCurrent(form);
form.setCommandListener(this);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
0 komentar:
Posting Komentar