5. Setelah penambahan plug in J2ME selesai, kemudian
tambahkan lagi WTK (Wireless ToolKit) yang dapat didownload di http://java.sun.com/products/sjwtoolkit/.
Setelah itu buka eclipse - window - preference - J2ME - device management -
import, browse hasil download-an tadi, klik Ok, klik refresh kemudian klik Ok.
Membuat Hello World
1. Jalankan Eclipse yang sudah terpasang
2. Pilih File - New - project - J2ME Midlet Suite klik next,
beri nama sesuai keinginan - next - finish.
3. Klik kanan pada scr disebelah kiri pilih New -
Other - Java ME MIDletj, beri nama kemudian klik finish.
4. Ketikkan source code di bawah ini :
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class hello extends MIDlet implements CommandListener
{
public hello() {
}
// Display
private Display
display;
// Main form
private Form form;
// For the message
private StringItem
stringItem;
// For the exit
command
private Command
exitCommand;
public void
commandAction(Command command, Displayable displayable) {
if
(displayable == form) {
if
(command == exitCommand) {
exitMIDlet();
}
}
}
public void
startApp() {
// Create form
stringItem =
new StringItem("Hello", "Hello World!");
form = new
Form(null, new Item[] {stringItem});
exitCommand =
new Command("Exit", Command.EXIT, 1);
form.addCommand(exitCommand);
form.setCommandListener(this);
// Get display
for drawning
display =
Display.getDisplay(this);
display.setCurrent(form);
}
// Your MIDlet
should not call pauseApp(), only system will call this life-cycle method
public void
pauseApp() {
}
// Your MIDlet
should not call destroyApp(), only system will call this life-cycle method
public void
destroyApp(boolean unconditional) {
}
public void
exitMIDlet() {
display.setCurrent(null);
notifyDestroyed();
}
}
5. Untuk menjalankan program tersebut klik Run kemudian
pilih run.