Membuat form sederhana menggunakan Eclipse Jdk midlet sangat mudah. Pertama pastikan plug-in dan feature miDlet telah terinstal pada Eclipse sehingga bisa digunakan untuk membuat program miDlet. Yang akan kita buat adalah tampilan seperti gambar disamping.
Pertama buka aplikasi eclipsenya kemudian klik file >> new >> project
Pertama buka aplikasi eclipsenya kemudian klik file >> new >> project
Kemudian setelah itu akan muncul tampilan nama project dan beri nama project >> next>>
Beri juga nama .jadnya dan klik next>>
Klik Finish
Klik ganda pada project kita misal siskom undip >>src >> klik kanan >> new >> package
Klik kanan >> new >> file
Kemudian masukkan listing berikut :
package L2N009012;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
public class FormMidlet extends MIDlet implements CommandListener{
private Form perDetails,resultForm;
private TextField name, address, contact, city;
private Command cmdOK, cmdExit,cmdBack;
private ChoiceGroup gender;
String[] genderType = { "Laki", "Perempuan" };
private Ticker ticker;
private Alert a;
private DateField dob, db;
private StringItem details;
public FormMidlet(){
cmdOK = new Command("PROSES", Command.SCREEN, 2);
cmdExit = new Command("SELESAI", Command.EXIT, 2);
//simpan = new Item("simpan", 2, Item.BUTTON);
resultForm = new Form("Input Anda adalah: ");
perDetails = new Form("Data Diri");
name = new TextField("Nama :", null, 20, TextField.ANY);
address = new TextField("Alamat :", null, 20, TextField.ANY);
city = new TextField("Kota :", null, 10, TextField.ANY);
contact = new TextField("Telepon:", null, 10, TextField.PHONENUMBER);
dob = new DateField("Tanggal lahir:", DateField.DATE);
gender = new ChoiceGroup("jenis kelamin", Choice.EXCLUSIVE, genderType, null);
ticker = new Ticker("Tugas MDP-Prima Widyaningrum-L2N009012");
a = new Alert("Data Diri", "Input sukses", null, null);
a.setTimeout(1000);
perDetails.append(name);
perDetails.append(address);
perDetails.append(city);
perDetails.append(contact);
perDetails.append(gender);
perDetails.append(dob);
perDetails.addCommand(cmdOK);
perDetails.addCommand(cmdExit);
perDetails.setTicker(ticker);
perDetails.setCommandListener(this);
}
protected void destroyApp(boolean arg0) {
notifyDestroyed();
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() {
Display.getDisplay(this).setCurrent(perDetails);
}
public void commandAction(Command arg0, Displayable arg1) {
if(arg0==cmdOK){
db = new DateField("hari ini", DateField.DATE);
db.setDate(new Date());
cmdBack = new Command("LANJUT", Command.EXIT, 2);
details = new StringItem(null, null);
details.setText("Nama : " + name.getString()
+ '\n' + "Alamat : "
+ address.getString()
+ '\n' + "Usia : "
+ ((db.getDate().getTime()-dob.getDate().getTime())/31557600/999)
+ " Tahun");
resultForm.append(details);
resultForm.addCommand(cmdBack);
resultForm.addCommand(cmdExit);
resultForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(a,resultForm);
}else if(arg0==cmdBack){
Display.getDisplay(this).setCurrent(perDetails);
}else if(arg0==cmdExit){
destroyApp(true);
}
}
}
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
public class FormMidlet extends MIDlet implements CommandListener{
private Form perDetails,resultForm;
private TextField name, address, contact, city;
private Command cmdOK, cmdExit,cmdBack;
private ChoiceGroup gender;
String[] genderType = { "Laki", "Perempuan" };
private Ticker ticker;
private Alert a;
private DateField dob, db;
private StringItem details;
public FormMidlet(){
cmdOK = new Command("PROSES", Command.SCREEN, 2);
cmdExit = new Command("SELESAI", Command.EXIT, 2);
//simpan = new Item("simpan", 2, Item.BUTTON);
resultForm = new Form("Input Anda adalah: ");
perDetails = new Form("Data Diri");
name = new TextField("Nama :", null, 20, TextField.ANY);
address = new TextField("Alamat :", null, 20, TextField.ANY);
city = new TextField("Kota :", null, 10, TextField.ANY);
contact = new TextField("Telepon:", null, 10, TextField.PHONENUMBER);
dob = new DateField("Tanggal lahir:", DateField.DATE);
gender = new ChoiceGroup("jenis kelamin", Choice.EXCLUSIVE, genderType, null);
ticker = new Ticker("Tugas MDP-Prima Widyaningrum-L2N009012");
a = new Alert("Data Diri", "Input sukses", null, null);
a.setTimeout(1000);
perDetails.append(name);
perDetails.append(address);
perDetails.append(city);
perDetails.append(contact);
perDetails.append(gender);
perDetails.append(dob);
perDetails.addCommand(cmdOK);
perDetails.addCommand(cmdExit);
perDetails.setTicker(ticker);
perDetails.setCommandListener(this);
}
protected void destroyApp(boolean arg0) {
notifyDestroyed();
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() {
Display.getDisplay(this).setCurrent(perDetails);
}
public void commandAction(Command arg0, Displayable arg1) {
if(arg0==cmdOK){
db = new DateField("hari ini", DateField.DATE);
db.setDate(new Date());
cmdBack = new Command("LANJUT", Command.EXIT, 2);
details = new StringItem(null, null);
details.setText("Nama : " + name.getString()
+ '\n' + "Alamat : "
+ address.getString()
+ '\n' + "Usia : "
+ ((db.getDate().getTime()-dob.getDate().getTime())/31557600/999)
+ " Tahun");
resultForm.append(details);
resultForm.addCommand(cmdBack);
resultForm.addCommand(cmdExit);
resultForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(a,resultForm);
}else if(arg0==cmdBack){
Display.getDisplay(this).setCurrent(perDetails);
}else if(arg0==cmdExit){
destroyApp(true);
}
}
}
Setelah itu klik kanan pada nama project kita pilih j2me >> create package seperti gambar berikut:
Ikuti langkah pada gambar, yaitu memasukkan resource agar aplikasi dapat jalan di Hp Ada..klik pada midlet >> add >> browser (yang dilingkari no 3) ketik nama project Anda >> OK
Untuk mencoba aplikasi pada mobile device atau hp Anda copy file yang ada di dalam deploy dan send pada hp Anda. Selamat mencoba :)
Tidak ada komentar:
Posting Komentar