Wednesday, September 26, 2012

LAB ACTIVITY 2 : Membuat MIDlet Dengan Menggunakan NetBeans Mobility Pack (Emulator)

Membuat MIDlet Dengan Menggunakan NetBeans Mobility Pack (Emulator)

Seperti program-program sebelumnya, yang diperlukan dalam membuat program ini adalah NetBeans dan NetBeans Mobility Pack yang harus sudah terinstall di komputer Anda.

 

Langkah - Langkah Membuat MIDlet sederhana :
  1. Membuat project baru
  2. Memilih kategori “Mobile
  3. Memilih “Mobile Application
  4. Beri nama project dan tentukan lokasinya (Hilangkan  tanda pada “Create Hello MIDlet”, dan ketikan "Hello World")
  5. Memilih Platform (optional)
  6. Membuat sebuah MIDlet barLangkah 7: Memilih MIDP “Category” dan MIDlet “File Typ
  7. Memilih MIDP “Category” dan MIDlet “File
  8. Memberi nama MIDlet
  9. Mengganti code yang dibuat secara otomatis dengan code program 
Source Code :

 import javax.microedition.midlet.*;

/**
 * @author jeffrey
 */
import javax.microedition.lcdui.*;

public class HelloMidlet extends MIDlet implements CommandListener {
    Display display;
    Command exitCommand = new Command ("Exit", Command.EXIT,1);
    Alert helloAlert;


    public HelloMidlet() {
            helloAlert  = new Alert("Hello MIDlet", "Hello, world!", null, AlertType.INFO);
            helloAlert.setTimeout(Alert.FOREVER);
            helloAlert.addCommand(exitCommand);
            helloAlert.setCommandListener(this);
    }

    public void startApp() {
            if (display==null) {
                display = Display.getDisplay(this);
            }
                display.setCurrent(helloAlert);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable d) {
          if (c==exitCommand) {
              destroyApp(true);
              notifyDestroyed();
           }
    }
}

10. Mengcompile dan Menjalankan (Run) MIDlet di Emulator kita
11. Menjalankan MIDlet kita di Emulator

Tampilan pada Emulator

 

No comments:

Post a Comment