import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Midlet_3 extends MIDlet implements CommandListener{
private Display display;
private Command cmdKeluar, cmdDaftar, cmdKembali, cmdSubmit;
private Form form;
private TextField nama, alamat, no_telp;
private Alert alert;
private ChoiceGroup jSpeedy;
public Midlet_3(){
display = Display.getDisplay(this);
//membuat form
form = new Form("Form Pendaftaran");
//menambahkan teks kedalam form
form.append("Selamat datang di TelkomSpeedy");
//membuat dua buah command, "Keluar" dan "Daftar"
cmdKeluar = new Command("Keluar", Command.EXIT,1);
cmdDaftar = new Command("Daftar", Command.SCREEN,1);
cmdSubmit = new Command("Submit", Command.SCREEN,2);
//menambahkan command kedalam form
form.addCommand(cmdKeluar);
form.addCommand(cmdDaftar);
form.setCommandListener(this);
}
public void startApp(){display.setCurrent(form);}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
private void form(){
form = new Form("Form Pendaftaran");
nama = new TextField("Nama: ", null, 35, TextField.ANY);
alamat = new TextField("Alamat: ", null, 50, TextField.ANY);
no_telp = new TextField("Telepon:", null, 25, TextField.PHONENUMBER);
jSpeedy = new ChoiceGroup("Speedy", Choice.EXCLUSIVE);
jSpeedy.append("Family", null);
jSpeedy.append("Bisnis", null);
jSpeedy.append("Executive", null);
//menambahkan append ke dalam form
form.append(nama);
form.append(alamat);
form.append(no_telp);
form.append(jSpeedy);
//menambahkan command ke dalam form
form.addCommand(cmdKeluar);
form.addCommand(cmdSubmit);
form.setCommandListener(this);
//menampilan form
display.setCurrent(form);
}
public void commandAction(Command c, Displayable s){
if(c == cmdKeluar){
destroyApp(false);
notifyDestroyed();
} else if (c==cmdDaftar){
form();
} else if (c==cmdSubmit) {
int indexs = jSpeedy.getSelectedIndex();
Alert info = new Alert("Informasi");
info.setType(AlertType.INFO);
String teks = null;
teks = nama.getString();
info.setString("Terima Kasih : \"" +teks+ "\" dengan berlanggangan paket " + jSpeedy.getString(indexs) + "\" Sudah Mendaftar");
info.setTimeout(Alert.FOREVER);
display.setCurrent(info);
}
}
}
Komentar