Kali ini saya akan membuat tugas dari mata kuliah mobile computing yaitu membuat form pengisian menggunakan J2ME, untuk software dan plugin nya ada di post sebelu-sebelumnya, so sobat bisa baca sendiri.OK...
Script codenya adalah seperti ini, jadi sesuaikan nama classnya dengan project sobat ya....
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class data_diri extends MIDlet implements CommandListener {
Display tampil;
Form FormInput, FormHasil;
TextField name, address, contact, email;
Command cmdOK, cmdExit,cmdBack;
ChoiceGroup gender;
Ticker ticker;
DateField date;
Alert alert;
public data_diri() {
cmdOK = new Command("SIMPAN", Command.OK, 1);
cmdBack = new Command("KEMBALI", Command.BACK, 1);
cmdExit = new Command("KELUAR", Command.EXIT, 1);
FormInput = new Form("Data Diri");
name = new TextField ("Nama : ", null, 50, TextField.ANY);
gender = new ChoiceGroup("Jenis Kelamin : ", Choice.POPUP);
gender.append("Laki-Laki", null);
gender.append("Perempuan", null);
address = new TextField ("Alamat : ", null, 50, TextField.ANY);
contact = new TextField ("Telepon : ", null, 20, TextField.PHONENUMBER);
email = new TextField ("E-mail : ", null, 20, TextField.EMAILADDR);
date = new DateField ("Tanggal lahir : ", DateField.DATE);
ticker = new Ticker("5302410074 - Tugas Mobile Computing");
alert = new Alert("ERROR", "Data yang anda masukkan belum lengkap", null, AlertType.ERROR);
FormInput.append(name);
FormInput.append(gender);
FormInput.append(address);
FormInput.append(contact);
FormInput.append(email);
FormInput.append(date);
FormInput.addCommand(cmdOK);
FormInput.addCommand(cmdExit);
FormInput.setTicker(ticker);
FormInput.setCommandListener(this);
}
protected void destroyApp(boolean arg0) {
notifyDestroyed();
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() {
if (tampil == null){
tampil = Display.getDisplay(this);
tampil.setCurrent(FormInput);
}
}
public void commandAction(Command c, Displayable d) {
if(c == cmdOK){
if (name.getString().equals("") || address.getString().equals("")
|| contact.getString().equals("") || email.getString().equals("")){
tampil.setCurrent(alert);
alert.setTimeout(Alert.FOREVER);
alert.addCommand(cmdBack);
}
else {
FormHasil = new Form("Biodata Anda: ");
FormHasil.deleteAll();
FormHasil.append ("Nama : " + name.getString()
+ '\n'+'\n' + "Jenis Kelamin : " + gender.getString(gender.getSelectedIndex())
+ '\n'+'\n' + "Alamat : " + address.getString()
+ '\n'+'\n' + "Contact : " + contact.getString()
+ '\n'+'\n' + "Email : " + email.getString()
+ '\n'+'\n' + "Tanggal Lahir : " + date.getDate());
FormHasil.addCommand(cmdBack);
FormHasil.addCommand(cmdExit);
FormHasil.setCommandListener(this);
tampil.setCurrent(FormHasil);
}
}else if(c==cmdBack){
Display.getDisplay(this).setCurrent(FormInput);
}else if(c==cmdExit){
destroyApp(true);
}
}
}
Nah berikut adalah screenshot hasilnya...
Gambar 1: Saat program dijalankan dan formnya diisi |
Gambar 2: Apabila salah satu form masih kosong akan muncul peringatan |
Gambar 3: Hasil program setelah form diisi semua dan disimpan |
-->> Terima Kasih <<--
0 komentar:
Posting Komentar