Kamis, 15 Januari 2015

TUTORIAL-1
LANGKAH-LANGKAH MEMBUAT PROJECT J2ME
INSERT DATA SECARA VISUAL MIDlet
DENGAN IDE NETBEANS


Pada kesempatan ini saya akan membagikan sedikit pengetahuan tentang langkah-langkah membuat project pada pemrograman J2ME menggunakan Netbeans.


Artikel ini menjelaskan tentang cara memulai membuat aplikasi J2ME (aplikasi Java untuk perangkat kecil, seperti selular,PDA dan lainnya) tanpa menuliskan kode kode programming (source-code) sedikitpun, karena artikel ini ditujukan kepada programmer yang belum pernah membuat aplikasi J2ME, mungkin tidak sedikit programmer desktop PC yang merasa terlalu sulit untuk membuat aplikasi J2ME untuk selular, mudah-mudahan artikel singkat ini bisa memberikan penjelasan yang cukup dan memberikan semangat yang positif untuk memulai membuat aplikasi J2ME. 
Membuat aplikasi J2ME tidak memerlukan banyak software yang rumit atau besar, salah satu software yang pasti diperlukan adalah J2SE SDK/JDK,dalam J2SE SDK/JDK ini terdapat runtime dan library untuk program Java secara umum termasuk juga untuk J2ME, pada saat artikel ini ditulis telah ada J2SE SDK v1.4.2 atau diatasnya. Untuk menulis source-code J2ME, maka kita memerlukan sebuah J2ME IDE (Integrated Development Environment), ada beberapa pilihan IDE yang diantaranya adalah Netbeans, Sun One Java Studio Mobility, CodeWarrior dan notepad (atau text editor lainnya), untungnya semua software IDE yang disebutkan ini dapat didownload gratis di website resmi masing-masing perusahaan, jadi untuk membuat program J2ME maka pihak developer tidak perlu mengeluarkan uang sama sekali untuk membeli software IDE. 
Pada artikel ini yang diulas adalah IDE dari Netbeans v7.1.2 dengan tambahan Netbeans Mobility Pack v4.1, tambahan ini diperlukan untuk membuat aplikasi J2ME, karena jika hanya dengan Netbean v7.1.2 hanya dapat membuat aplikasi Java saja, Netbeans Mobility Pack adalah module-module aplikasi J2ME dan emulator device untuk testing dalam PC. IDE lainnya boleh dicoba tapi dianjurkan memakai Netbeans v7.1.2 karena versi ini sangat mudah dioperasikan dan dirasakan cukup cepat dibanding IDE lainnya dalam hal loading, compiling, running dan debugging.
Langkah yang dilakukan untuk memulai pembuatan aplikasi J2ME adalah:
1. Install J2SE SDK v1.4.2
2. Install Netbeans v7.1.2 
3. Install Netbeans Mobility Pack v4.1
4. Install J2ME Platmform SDK 3.0.5 atau diatasnya

Bagi yang baru belajar J2ME Silahkan mempelajari video tutorial dibawah ini :



ini adalah source codenya :


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;
    }

    /**
     * Returns a display instance.
     *
     * @return the display instance.
     */
    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 ini gambar tampilannya :


 Tombol Ok ditekan menghasilkan :



Selamat Mencoba Semoga Berhasil....

Untuk video tutorial insert gambar atau image saya bahas pada entri selanjutnya ...

1 komentar:

  1. Terimakasih tutorialnya, sangat bermanfaat dan menambah ilmu. dilain waktu saya akan coba tutorial ini, sharing" diyoutube juga kak tutorial nya biar lebih mudah dalam mempraktekkannya.

    Kungjungi Website kampus saya http://www.atmaluhur.ac.id

    dan Website saya https://ernaningsih.mahasiswa.atmaluhur.ac.id

    BalasHapus