TUTORIAL-2 (Lanjutan)
MENAMBAHKAN IMAGE PADA FORM
APLIKASI J2ME MENGGUNAKAN
IDE NETBEANS
MENAMBAHKAN IMAGE PADA FORM
APLIKASI J2ME MENGGUNAKAN
IDE NETBEANS
Salam bertemu kembali.
Pada tutorial sebelumnya saya sempat menyinggung dan menjanjikan langkah-langkah menambahkan gambar atau image pada form aplikasi yang sudah kita buat sebelumnya.
Silahkan simak video tutorial berikut ini :
dibawah ini adalah source code nya :
package paketRekam;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
/**
* @author benpro
*/
public class RekamMIDlet extends MIDlet implements CommandListener {
private boolean midletPaused = false;
//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">
private Form formRekam;
private TextField textNama;
private TextField textTgllhr;
private TextField textNim;
private ChoiceGroup CgProdi;
private ChoiceGroup CgJnsKelamin;
private Form formHasil;
private StringItem itemNama;
private StringItem itemNim;
private StringItem itemProdi;
private StringItem itemTgllhr;
private StringItem itemJnsKelamin;
private Command exitCommand;
private Command okCommand;
private Command backCommand;
private Command exitCommand1;
private Command okCommand1;
private Command exitCommand2;
private Image image1;
//</editor-fold>
/**
* The RekamMIDlet constructor.
*/
public RekamMIDlet() {
}
private void initialize() {
// write pre-initialize user code here
// write post-initialize user code here
}
public void startMIDlet() {
// write pre-action user code here
switchDisplayable(null, getFormRekam());
// write post-action user code here
}
public void resumeMIDlet() {
// write pre-action user code here
// write post-action user code here
}
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
}
public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
if (displayable == formHasil) {
if (command == backCommand) {
// write pre-action user code here
switchDisplayable(null, getFormRekam());
// write post-action user code here
} else if (command == exitCommand1) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
}
} else if (displayable == formRekam) {
if (command == exitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
} else if (command == okCommand) {
// write pre-action user code here
switchDisplayable(null, getFormHasil());
// write post-action user code here
}
}
// write post-action user code here
}
public Form getFormRekam() {
if (formRekam == null) {
// write pre-init user code here
formRekam = new Form("Form Rekam Data", new Item[]{getTextNama(), getTextNim(), getTextTgllhr(), getCgJnsKelamin(), getCgProdi()});
formRekam.addCommand(getOkCommand());
formRekam.addCommand(getExitCommand());
formRekam.setCommandListener(this);
// write post-init user code here
}
return formRekam;
}
public TextField getTextNama() {
if (textNama == null) {
// write pre-init user code here
textNama = new TextField("Nama :", null, 32, TextField.ANY);
textNama.setLayout(ImageItem.LAYOUT_LEFT | Item.LAYOUT_2);
// write post-init user code here
}
return textNama;
}
public TextField getTextNim() {
if (textNim == null) {
// write pre-init user code here
textNim = new TextField("N I M :", null, 32, TextField.ANY);
textNim.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
// write post-init user code here
}
return textNim;
}
public TextField getTextTgllhr() {
if (textTgllhr == null) {
// write pre-init user code here
textTgllhr = new TextField("Tanggal Lahir (dd/mm/yyyy) :", null, 32, TextField.ANY);
textTgllhr.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
// write post-init user code here
}
return textTgllhr;
}
public ChoiceGroup getCgJnsKelamin() {
if (CgJnsKelamin == null) {
// write pre-init user code here
CgJnsKelamin = new ChoiceGroup("Jenis Kelamin :", Choice.POPUP);
CgJnsKelamin.append("Laki-laki", null);
CgJnsKelamin.append("Perempuan", null);
CgJnsKelamin.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
CgJnsKelamin.setSelectedFlags(new boolean[]{true, false});
// write post-init user code here
}
return CgJnsKelamin;
}
public ChoiceGroup getCgProdi() {
if (CgProdi == null) {
// write pre-init user code here
CgProdi = new ChoiceGroup("Prodi :", Choice.EXCLUSIVE);
CgProdi.append("Teknik Informatika", null);
CgProdi.append("Sistem Informasi", null);
CgProdi.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
CgProdi.setSelectedFlags(new boolean[]{false, false});
// write post-init user code here
}
return CgProdi;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">
/**
* 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;
}
public Command getOkCommand() {
if (okCommand == null) {
// write pre-init user code here
okCommand = new Command("Ok", Command.OK, 0);
// write post-init user code here
}
return okCommand;
}
public Form getFormHasil() {
if (formHasil == null) {
// write pre-init user code here
formHasil = new Form("Form Hasil Rekam", new Item[]{getItemNama(), getItemNim(), getItemTgllhr(), getItemJnsKelamin(), getItemProdi()});
formHasil.addCommand(getBackCommand());
formHasil.addCommand(getExitCommand1());
formHasil.setCommandListener(this);
// write post-init user code here
}
return formHasil;
}
public StringItem getItemNama() {
if (itemNama == null) {
// write pre-init user code here
itemNama = new StringItem("Nama :", textNama.getString());
// write post-init user code here
}
return itemNama;
}
public StringItem getItemNim() {
if (itemNim == null) {
// write pre-init user code here
itemNim = new StringItem("N I M :", textNim.getString());
// write post-init user code here
}
return itemNim;
}
public StringItem getItemTgllhr() {
if (itemTgllhr == null) {
// write pre-init user code here
itemTgllhr = new StringItem("Tanggal Lahir :", textTgllhr.getString());
// write post-init user code here
}
return itemTgllhr;
}
public StringItem getItemJnsKelamin() {
if (itemJnsKelamin == null) {
// write pre-init user code here
itemJnsKelamin = new StringItem("Jenis Kelamin :", CgJnsKelamin.getString(CgJnsKelamin.getSelectedIndex()));
// write post-init user code here
}
return itemJnsKelamin;
}
public StringItem getItemProdi() {
if (itemProdi == null) {
// write pre-init user code here
itemProdi = new StringItem("Prodi :", CgProdi.getString(CgProdi.getSelectedIndex()));
// write post-init user code here
}
return itemProdi;
}
public Command getBackCommand() {
if (backCommand == null) {
// write pre-init user code here
backCommand = new Command("Kembali", Command.SCREEN, 0);
// write post-init user code here
}
return backCommand;
}
public Command getExitCommand1() {
if (exitCommand1 == null) {
// write pre-init user code here
exitCommand1 = new Command("Keluar", Command.SCREEN, 0);
// write post-init user code here
}
return exitCommand1;
}
public Command getExitCommand2() {
if (exitCommand2 == null) {
// write pre-init user code here
exitCommand2 = new Command("Keluar", Command.SCREEN, 0);
// write post-init user code here
}
return exitCommand2;
}
public Command getOkCommand1() {
if (okCommand1 == null) {
// write pre-init user code here
okCommand1 = new Command("Ok", Command.OK, 0);
// write post-init user code here
}
return okCommand1;
}
public Image getImage1() {
if (image1 == null) {
// write pre-init user code here
try {
image1 = Image.createImage("/paketRekam/logo_unkris.png");
} catch (java.io.IOException e)
{
}
// write post-init user code here
}
return image1;
}
public Display getDisplay() {
return Display.getDisplay(this);
}
/**
* Exits MIDlet.
*/
public void exitMIDlet() {
switchDisplayable(null, null);
destroyApp(true);
notifyDestroyed();
}
public void startApp() {
if (midletPaused) {
resumeMIDlet();
} else {
initialize();
startMIDlet();
}
midletPaused = false;
}
public void pauseApp() {
midletPaused = true;
}
public void destroyApp(boolean unconditional) {
}
}
dan berikut ini tampilannya :
Terima kasih atas perhatiannya dan dimohon komentarnya.
Semoga Sukses Selalu
Tidak ada komentar:
Posting Komentar