Skip to content

J2ME midlet with Netbeans: Hello world!

The default Netbeans GUI builder sux by definition.

This is a small howto for the empty j2me project developing.

  1. File -> New Project
  2. Java ME -> Mobile Application -> Next
  3. Deselect “Create Hello MIDlet”. Finish.

That will create an empty project.

  1. Than add a new package with a specified name, ex. “newPackage”.
  2. Add a newempty  Java Class file in this package, ex. “helloWorld.java”.

The example of the “helloWorld” j2me app code:

package newPackage;

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

public class helloWorld extends MIDlet implements CommandListener{

private boolean midletPaused = false;

private Display display;

private Command cmdExit = new Command(“exitCmd”, Command.EXIT, 0);

private Form form1;

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {

this.midletPaused = true;

}

protected void startApp() {

if (this.display == null) {

this.display = Display.getDisplay(this);

this.form1 = new Form(“newForm”);

form1.setCommandListener(this);

form1.addCommand(this.cmdExit);

this.display.setCurrent(form1);

}

this.midletPaused = false;

}

public void commandAction(Command c, Displayable d) {

if (d == this.form1) {

if (c == this.cmdExit) {

notifyDestroyed();

}

}

}

}

  1. Open the project properties dialog (right click on the project name).
  2. Application Descriptor -> MIDlet -> Add
  3. MIDlet Name: helloWorld (the name of the main class, better)
  4. MIDlet Class: newPackage.helloWorld (the ‘main’ class of the project)
  5. Ok.

Save, compile, build, and have fun.

P.S. Microemulator is a free cewl tool for running j2me apps on your PC.

Categories: Java/J2ME.

Tags: , , ,

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.