APLIKASI PERTAMA

Halo.. pembaca ..

Wah sudah lama sekali saya tidak posting hampir sebulan kira kira .

Dalam posting kali ini saya mau berbagi kegiatan kuliah saya selama sebulan ini

Bulan ini kuliah saya di seamolec diperpadat dan yang akan saya share adalah hasil salah satu mata kuliah saya yaitu PBO(Pemrogaman Berbasis Objek)

Dan hasilnya adalah sebuah aplikasi berbasis java mobile yang dibuat dengan software pengolah Netbean IDE 6.8

Aplikasi yang saya buat adalah aplikasi menghitung gerak lurus beraturan

yaitu sebuah aplikasi yang dapat menghitung
Kecepatan

Jarak

Waktu

Berikut scren shoot nya

Saya membuatnya Cuma menggunakan visual middlet dan sedikit saja mengedit source nya
hehehe maaf ya kalo jelek baru belajar soalnya

nah kawan kawan kalu mau coba buat
silahkan

jangan lupa komentnya ya

ini flownya

Dan command action sourcenya

dan berikut source codenya

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.pim.PIM;
import org.netbeans.microedition.lcdui.SplashScreen;
import org.netbeans.microedition.lcdui.pda.PIMBrowser;

/**
 * @author Fajar
 */
public class aplikasi1 extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    //
    private List list;
    private Form KECEPATAN;
    private StringItem stringItem;
    private TextField Jarak;
    private TextField waktu;
    private Form JARAK;
    private TextField kecepatan2;
    private TextField waktu2;
    private StringItem stringItem1;
    private Form WAKTU;
    private TextField kecepatan3;
    private TextField jarak3;
    private StringItem stringItem2;
    private SplashScreen splashScreen;
    private SplashScreen splashScreen2;
    private SplashScreen splashScreen1;
    private Command exitCommand;
    private Command okCommand;
    private Command OK1;
    private Command backCommand;
    private Command OK2;
    private Command OK3;
    private Command backCommand1;
    private Command backCommand2;
    private Image image1;
    private Image image3;
    private Image image2;
    //

    /**
     * The aplikasi1 constructor.
     */
    public aplikasi1() {
    }

    //
    //
    //
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> 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, getList());
        // 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 <code>display</code> instance is taken from <code>getDisplay</code> 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 <code>null</code>, then <code>nextDisplayable</code> 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
        if (displayable == JARAK) {
            if (command == OK2) {
                String pilih = getList().getString(getList().getSelectedIndex());
                if (pilih.equals("JARAK")) {
                    float kcpt2 = Float.parseFloat(getKecepatan2().getString());
                    float wkt2 = Float.parseFloat(getWaktu2().getString());
                    float s = kcpt2 * wkt2;
                    getStringItem1().setText("Jarak yang dampat anda tempuh adalah " + s + " Km");
                }                // write pre-action user code here

                // write post-action user code here
            } else if (command == backCommand) {
                // write pre-action user code here
                switchDisplayable(null, getList());
                // write post-action user code here
            }
        } else if (displayable == KECEPATAN) {
            if (command == OK1) {
                String pilih = getList().getString(getList().getSelectedIndex());
                if (pilih.equals("KECEPATAN")) {
                    float jrk = Float.parseFloat(getJarak().getString());
                    float wkt = Float.parseFloat(getWaktu().getString());
                    float v = jrk / wkt;
                    getStringItem().setText("Kecepatan yang dibutuhkan: " + v + " Km/jam");

                }
                // write pre-action user code here

                // write post-action user code here
            } else if (command == backCommand1) {
                // write pre-action user code here
                switchDisplayable(null, getList());
                // write post-action user code here
            }
        } else if (displayable == WAKTU) {
            if (command == OK3) {
                String pilih = getList().getString(getList().getSelectedIndex());
                if (pilih.equals("WAKTU")) {
                    float jrk = Float.parseFloat(getJarak3().getString());
                    float kcp = Float.parseFloat(getKecepatan3().getString());
                    float t = jrk / kcp;
                    getStringItem2().setText("Waktu yang dibutuhkan: " + t + " jam");

                }
                // write pre-action user code here

                // write post-action user code here
            } else if (command == backCommand2) {
                // write pre-action user code here
                switchDisplayable(null, getList());
                // write post-action user code here
            }
        } else if (displayable == list) {
            if (command == List.SELECT_COMMAND) {
                // write pre-action user code here
                listAction();
                // write post-action user code here
            } else if (command == exitCommand) {
                // write pre-action user code here

                // write post-action user code here
            } else if (command == okCommand) {

                // write pre-action user code here
                listAction();
                // write post-action user code here
            }
        } else if (displayable == splashScreen) {
            if (command == SplashScreen.DISMISS_COMMAND) {
                // write pre-action user code here
                switchDisplayable(null, getKECEPATAN());
                // write post-action user code here
            }
        } else if (displayable == splashScreen1) {
            if (command == SplashScreen.DISMISS_COMMAND) {
                // write pre-action user code here
                switchDisplayable(null, getJARAK());
                // write post-action user code here
            }
        } else if (displayable == splashScreen2) {
            if (command == SplashScreen.DISMISS_COMMAND) {
                // write pre-action user code here
                switchDisplayable(null, getWAKTU());
                // write post-action user code here
            }
        }
        // write post-action user code here
    }
    //

    //
    /**
     * Returns an initiliazed instance of list component.
     * @return the initialized component instance
     */
    public List getList() {
        if (list == null) {
            // write pre-init user code here
            list = new List("PILIH YANG INGIN ANDA HITUNG", Choice.IMPLICIT);
            list.append("KECEPATAN", null);
            list.append("WAKTU", null);
            list.append("JARAK", null);
            list.addCommand(getExitCommand());
            list.addCommand(getOkCommand());
            list.setCommandListener(this);
            list.setSelectedFlags(new boolean[] { true, false, false });
            // write post-init user code here
        }
        return list;
    }
    //

    //
    /**
     * Performs an action assigned to the selected list element in the list component.
     */
    public void listAction() {
        // enter pre-action user code here
        String __selectedString = getList().getString(getList().getSelectedIndex());
        if (__selectedString != null) {
            if (__selectedString.equals("KECEPATAN")) {
                // write pre-action user code here
                switchDisplayable(null, getSplashScreen());
                // write post-action user code here
            } else if (__selectedString.equals("WAKTU")) {
                // write pre-action user code here
                switchDisplayable(null, getSplashScreen2());
                // write post-action user code here
            } else if (__selectedString.equals("JARAK")) {
                // write pre-action user code here
                switchDisplayable(null, getSplashScreen1());
                // write post-action user code here
            }
        }
        // enter post-action user code here
    }
    //

    //
    /**
     * Returns an initiliazed 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 initiliazed instance of KECEPATAN component.
     * @return the initialized component instance
     */
    public Form getKECEPATAN() {
        if (KECEPATAN == null) {
            // write pre-init user code here
            KECEPATAN = new Form("KECEPATAN", new Item[] { getJarak(), getWaktu(), getStringItem() });
            KECEPATAN.addCommand(getOK1());
            KECEPATAN.addCommand(getBackCommand1());
            KECEPATAN.setCommandListener(this);
            // write post-init user code here
        }
        return KECEPATAN;
    }
    //

    //
    /**
     * Returns an initiliazed instance of okCommand component.
     * @return the initialized component instance
     */
    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;
    }
    //

    //
    /**
     * Returns an initiliazed instance of WAKTU component.
     * @return the initialized component instance
     */
    public Form getWAKTU() {
        if (WAKTU == null) {
            // write pre-init user code here
            WAKTU = new Form("WAKTU", new Item[] { getJarak3(), getKecepatan3(), getStringItem2() });
            WAKTU.addCommand(getOK3());
            WAKTU.addCommand(getBackCommand2());
            WAKTU.setCommandListener(this);
            // write post-init user code here
        }
        return WAKTU;
    }
    //

    //
    /**
     * Returns an initiliazed instance of JARAK component.
     * @return the initialized component instance
     */
    public Form getJARAK() {
        if (JARAK == null) {
            // write pre-init user code here
            JARAK = new Form("JARAK", new Item[] { getKecepatan2(), getWaktu2(), getStringItem1() });
            JARAK.addCommand(getOK2());
            JARAK.addCommand(getBackCommand());
            JARAK.setCommandListener(this);
            // write post-init user code here
        }
        return JARAK;
    }
    //
    //

    //
    /**
     * Returns an initiliazed instance of OK1 component.
     * @return the initialized component instance
     */
    public Command getOK1() {
        if (OK1 == null) {
            // write pre-init user code here
            OK1 = new Command("Ok", Command.OK, 0);
            // write post-init user code here
        }
        return OK1;
    }
    //

    //
    /**
     * Returns an initiliazed instance of Jarak component.
     * @return the initialized component instance
     */
    public TextField getJarak() {
        if (Jarak == null) {
                // write pre-init user code here
            Jarak = new TextField("Masukan jarak yang anda tempuh", null, 32, TextField.NUMERIC);
                // write post-init user code here
        }
        return Jarak;
    }
    //
    //

    //
    /**
     * Returns an initiliazed instance of waktu component.
     * @return the initialized component instance
     */
    public TextField getWaktu() {
        if (waktu == null) {
                // write pre-init user code here
            waktu = new TextField("Masukan waktu yang anda inginkan", null, 32, TextField.NUMERIC);
                // write post-init user code here
        }
        return waktu;
    }
    //

    //
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {
                // write pre-init user code here
            stringItem = new StringItem("", null);
                // write post-init user code here
        }
        return stringItem;
    }
    //
    //

    //
    /**
     * Returns an initiliazed instance of kecepatan2 component.
     * @return the initialized component instance
     */
    public TextField getKecepatan2() {
        if (kecepatan2 == null) {
                // write pre-init user code here
            kecepatan2 = new TextField("Masukan Kecepatan yang anda inginkan<km/jam>", null, 32, TextField.NUMERIC);
                // write post-init user code here
        }
        return kecepatan2;
    }
    //
    //

    //
    /**
     * Returns an initiliazed instance of waktu2 component.
     * @return the initialized component instance
     */
    public TextField getWaktu2() {
        if (waktu2 == null) {
                // write pre-init user code here
            waktu2 = new TextField("Masukan waktu yang anda Inginkan", null, 32, TextField.NUMERIC);
                // write post-init user code here
        }
        return waktu2;
    }
    //

    //
    /**
     * Returns an initiliazed instance of OK2 component.
     * @return the initialized component instance
     */
    public Command getOK2() {
        if (OK2 == null) {
                // write pre-init user code here
            OK2 = new Command("Ok", Command.OK, 0);
                // write post-init user code here
        }
        return OK2;
    }
    //

    //
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {
                // write pre-init user code here
            backCommand = new Command("Back", Command.BACK, 0);
                // write post-init user code here
        }
        return backCommand;
    }
    //

    //
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {
                // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 0);
                // write post-init user code here
        }
        return backCommand1;
    }
    //
    //

    //
    /**
     * Returns an initiliazed instance of OK3 component.
     * @return the initialized component instance
     */
    public Command getOK3() {
        if (OK3 == null) {
                // write pre-init user code here
            OK3 = new Command("Ok", Command.OK, 0);
                // write post-init user code here
        }
        return OK3;
    }
    //

    //
    /**
     * Returns an initiliazed instance of backCommand2 component.
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {
                // write pre-init user code here
            backCommand2 = new Command("Back", Command.BACK, 0);
                // write post-init user code here
        }
        return backCommand2;
    }
    //
        //

    //
    /**
     * Returns an initiliazed instance of jarak3 component.
     * @return the initialized component instance
     */
    public TextField getJarak3() {
        if (jarak3 == null) {
                // write pre-init user code here
            jarak3 = new TextField("Masukan jarak yang anda tempuh", null, 32, TextField.NUMERIC);
                // write post-init user code here
        }
        return jarak3;
    }
    //
        //

    //
    /**
     * Returns an initiliazed instance of kecepatan3 component.
     * @return the initialized component instance
     */
    public TextField getKecepatan3() {
        if (kecepatan3 == null) {
                // write pre-init user code here
            kecepatan3 = new TextField("masukan kecepatan <km/jam>", null, 32, TextField.NUMERIC);
                // write post-init user code here
        }
        return kecepatan3;
    }
    //

    //
    /**
     * Returns an initiliazed instance of stringItem1 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem1() {
        if (stringItem1 == null) {
            // write pre-init user code here
            stringItem1 = new StringItem("", null);
            // write post-init user code here
        }
        return stringItem1;
    }
    //

    //
    /**
     * Returns an initiliazed instance of stringItem2 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem2() {
        if (stringItem2 == null) {
            // write pre-init user code here
            stringItem2 = new StringItem("", null);
            // write post-init user code here
        }
        return stringItem2;
    }
    //

    //
    /**
     * Returns an initiliazed instance of splashScreen component.
     * @return the initialized component instance
     */
    public SplashScreen getSplashScreen() {
        if (splashScreen == null) {
            // write pre-init user code here
            splashScreen = new SplashScreen(getDisplay());
            splashScreen.setTitle("MENGHITUNG KECEPATAN");
            splashScreen.setCommandListener(this);
            splashScreen.setImage(getImage1());
            splashScreen.setTimeout(1000);
            // write post-init user code here
        }
        return splashScreen;
    }
    //

    //
    /**
     * Returns an initiliazed instance of image1 component.
     * @return the initialized component instance
     */
    public Image getImage1() {
        if (image1 == null) {
            // write pre-init user code here
            try {
                image1 = Image.createImage("/speed blog[5].jpg");
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
            // write post-init user code here
        }
        return image1;
    }
    //

    //
    /**
     * Returns an initiliazed instance of splashScreen1 component.
     * @return the initialized component instance
     */
    public SplashScreen getSplashScreen1() {
        if (splashScreen1 == null) {
            // write pre-init user code here
            splashScreen1 = new SplashScreen(getDisplay());
            splashScreen1.setTitle("MENGHITUNG JARAK");
            splashScreen1.setCommandListener(this);
            splashScreen1.setImage(getImage2());
            splashScreen1.setTimeout(1000);
            // write post-init user code here
        }
        return splashScreen1;
    }
    //

    //
    /**
     * Returns an initiliazed instance of splashScreen2 component.
     * @return the initialized component instance
     */
    public SplashScreen getSplashScreen2() {
        if (splashScreen2 == null) {
            // write pre-init user code here
            splashScreen2 = new SplashScreen(getDisplay());
            splashScreen2.setTitle("MENGHITUNG WAKTU");
            splashScreen2.setCommandListener(this);
            splashScreen2.setImage(getImage3());
            splashScreen2.setTimeout(1000);
            // write post-init user code here
        }
        return splashScreen2;
    }
    //

    //
    /**
     * Returns an initiliazed instance of image3 component.
     * @return the initialized component instance
     */
    public Image getImage3() {
        if (image3 == null) {
            // write pre-init user code here
            try {
                image3 = Image.createImage("/waktu.jpg");
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
            // write post-init user code here
        }
        return image3;
    }
    //

    //
    /**
     * Returns an initiliazed instance of image2 component.
     * @return the initialized component instance
     */
    public Image getImage2() {
        if (image2 == null) {
            // write pre-init user code here
            try {
                image2 = Image.createImage("/distance_measure.jpeg");
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
            // write post-init user code here
        }
        return image2;
    }
    //

    /**
     * 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();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
}

9 thoughts on “APLIKASI PERTAMA

  1. mas….sy masih sdikit bingung ne….kekmana caranya memanggil class atau MIDlet yang kita buat sebelumnya….padahal untuk splascren dan menu utama kita membuatnya dgn visual MIDLet …..apa bisa digabung tu?? ruslinasty@yahoo.com

    • bisa mas
      kalau mas mau memanggil class yang sebelumnya sudah mas buat
      tinggal memasukanya saja ke Visual Midlletnya dengan cara
      pergi ke menu palette lalu klik kanan di situ kemudian mulih palette manager lalu mas pulih add to pallet
      nah tinggal piling nama project nya lalu nama classnya kemudian kalu sudah mas tinggal klik kanan add di visual middletnya lalu hubungkan
      kalau aplikasi saya yang ini saya mngedit coding yang ada pada source visual middletnya
      Terima kasih ya mas Komentarnya
      kalau belum mengerti
      Boleh bertanya lagi kok
      Sekali lagi terima kasih

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s