Nama : Gusty Cholid Fahrudi
Nim : E3210320
Prodi : TKK-A
Script J2ME Aplikasi Mobile Data Pribadi
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author Gusty
*/
public class HelloMIDlet extends MIDlet implements CommandListener {
//inisialisasi properti
private Display display;
private Form fmMY_Data_Pribadi;
private Form fmHasil;
private Command cmYa;
private Command cmKeluar;
private Command cmKembali;
private TextField tfNama;
private TextField tfNIM;
private TextField tfJurusan;
private TextField tfProdi;
private TextField tfAlamat;
private ChoiceGroup cgJenisKelamin;
private int choiceGroupIndex;
private StringItem siNama, siNIM, siJurusan, siProdi, siAlamat, siJenisKelamin;
private boolean midletPaused = false;
//
private Command exitCommand;
private Form form;
private StringItem stringItem;
//
public HelloMIDlet() {
}
//
//
//
/**
* Initializes the application. It is called only once when the MIDlet is
* started. The method is called before the
*
startMIDlet method.*/
private void initialize() {
// write pre-initialize user code here
// write post-initialize user code here
}
//
//
/**
* Performs an action assigned to the Mobile Device - MIDlet Started point.
*/
public void startMIDlet() {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
}
//
//
/**
* Performs an action assigned to the Mobile Device - MIDlet Resumed point.
*/
public void resumeMIDlet() {
// write pre-action user code here
// write post-action user code here
}
//
//
/**
* Switches a current displayable in a display. The
*
display instance is taken from*
getDisplay method. This method is used by all actions in the* design for switching displayable.
*
* @param alert the Alert which is temporarily set to the display; if
*
null, then*
nextDisplayable is set immediately* @param nextDisplayable the Displayable to be set
*/
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
// write pre-switch user code here
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
// write post-switch user code here
}
//
//
/**
* Called by a system to indicated that a command has been invoked on a
* particular displayable.
*
* @param command the Command that was invoked
* @param displayable the Displayable where the command was invoked
*/
public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
String nama,nim,jurusan,prodi,alamat,JenisKelamin = null;
//jika tombol/command OK ditekan
if(command == cmYa){
//mendapatkan inputan user
nama = tfNama.getString();
nim = tfNIM.getString();
jurusan = tfJurusan.getString();
prodi = tfProdi.getString();
alamat = tfAlamat.getString();
JenisKelamin = cgJenisKelamin.getString(cgJenisKelamin.getSelectedIndex());
//memasukkan hasil input ke StringItem
siNama.setText(nama);
siNIM.setText(nim);
siJurusan.setText(jurusan);
siProdi.setText(prodi);
siAlamat.setText(alamat);
siJenisKelamin.setText(JenisKelamin);
//menampilkan form hasil setelah cmOk ditekan
display.setCurrent(fmHasil);
} else if(command == cmKeluar){ //jika tombol/command Exit ditekan
destroyApp(true);
notifyDestroyed();
} else if(command == cmKembali){ //jika tombol/command Back ditekan
//menampilkan kembali form DataPribadi sebagai tampilan default/awal
display.setCurrent(fmMY_Data_Pribadi);
}
if (displayable == form) {
if (command == exitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
}
}
// write post-action user code here
}
//
//
/**
* Returns an initialized instance of exitCommand component.
*
* @return the initialized component instance
*/
public Command getExitCommand() {
if (exitCommand == null) {
// write pre-init user code here
exitCommand = new Command("Exit", Command.EXIT, 0);
// write post-init user code here
}
return exitCommand;
}
//
//
/**
* Returns an initialized instance of form component.
*
* @return the initialized component instance
*/
public Form getForm() {
if (form == null) {
// write pre-init user code here
form = new Form("Welcome", new Item[]{getStringItem()});
form.addCommand(getExitCommand());
form.setCommandListener(this);
// write post-init user code here
}
return form;
}
//
//
/**
* Returns an initialized instance of stringItem component.
*
* @return the initialized component instance
*/
public StringItem getStringItem() {
if (stringItem == null) {
// write pre-init user code here
stringItem = new StringItem("Hello", "Hello, World!");
// write post-init user code here
}
return stringItem;
}
//
public Display getDisplay() {
return Display.getDisplay(this);
}
public void exitMIDlet() {
switchDisplayable(null, null);
destroyApp(true);
notifyDestroyed();
}
public void startApp() {
display = Display.getDisplay(this);
//membuat tombol
cmKeluar = new Command("Exit", Command.EXIT, 0);
cmYa = new Command("Ok", Command.SCREEN, 0);
cmKembali = new Command("Back", Command.BACK, 0);
//textfield untuk data pribadi
tfNama = new TextField("Nama: ", "", 30, TextField.ANY);
tfNIM = new TextField("NIM:", "", 30, TextField.ANY);
tfJurusan = new TextField ("Jurusan:", "", 30, TextField.ANY);
tfProdi = new TextField("Program Studi: ", "", 30, TextField.ANY);
tfAlamat = new TextField("Alamat: ", "", 30, TextField.ANY);
//pemilihan Jenis Kelamin
cgJenisKelamin = new ChoiceGroup("Jenis Kelamin", Choice.EXCLUSIVE);
//meng-append pilihan atau choice
cgJenisKelamin.append("Pria", null);
cgJenisKelamin.append("Wanita", null);
//membuat form dan memasukkan komponen
fmMY_Data_Pribadi = new Form("Politeknik Negeri Jember");
fmMY_Data_Pribadi.addCommand(cmKeluar);
fmMY_Data_Pribadi.addCommand(cmYa);
fmMY_Data_Pribadi.append(tfNama);
fmMY_Data_Pribadi.append(tfNIM);
fmMY_Data_Pribadi.append(tfJurusan);
fmMY_Data_Pribadi.append(tfProdi);
choiceGroupIndex = fmMY_Data_Pribadi.append(cgJenisKelamin);
fmMY_Data_Pribadi.append(tfAlamat);
fmMY_Data_Pribadi.setCommandListener(this);
//membuat form hasil input user
fmHasil = new Form("Politeknik Negeri Jember");
//membuat string item untuk menampilkan text dan pilihan yang diisi
siNama = new StringItem("Nama: ", null);
siNIM = new StringItem ("NIM : ", null);
siJurusan = new StringItem ("Jurusan : ", null);
siProdi = new StringItem("Program Studi: ", null);
siJenisKelamin = new StringItem("Jenis Kelamin: ", null);
siAlamat = new StringItem("Alamat: ", null);
//menampilkan StringItem yang nanti akan diisi oleh data hasil input user
fmHasil.append(siNama);
fmHasil.append(siNIM);
fmHasil.append(siJurusan);
fmHasil.append(siProdi);
fmHasil.append(siJenisKelamin);
fmHasil.append(siAlamat);
//menambahkan command
fmHasil.addCommand(cmKembali);
fmHasil.setCommandListener(this);
//menampilkan form DataPribadi sebagai tampilan awal
display.setCurrent(fmMY_Data_Pribadi);
midletPaused = false;
}
public void pauseApp() {
midletPaused = true;
}
public void destroyApp(boolean unconditional) {
}
}
Output
Masukkan Data Diri Anda Dengan Klik Tombol Yang Tersedia
Contoh 1
Setelah Selesai Diisi Semuannya Klik Menu - Ok
contoh 2
Selamat Mencoba Semoga Sukses
Warning Harap Kritik dan Saran Anda Dengan Program Diatas
maz klo'mw gnti tmpilan hpnya gmna...
BalasHapusprogram ini bisa gak klo dibuat secara terpisah misalnya classnya sendiri....?????
BalasHapusskripx g bisa di minimalisir gan ?//////
BalasHapus