Im Menü File->New->Project->J2ME->J2ME Midlet Suite eine neue J2ME
Midlet Suite anlegen
Name ist J2MEHelloWorld, als Plattform wählt man CLDC1.1/MIDP2.0
Evtl. muss man die J2ME Klassen unter Order and Export die J2ME
library mit einbinden, da sonst später Fehler auftreten (ala
java.lang.Object not found)
Im Menü File->New->Other->J2ME->J2ME Midlet ein neues Midlet
anlegen
Als Name "J2MEHelloWorld" angeben
Darauf achten, dass "Add To Application Descriptor" aktiviert
ist
Es folgt der Midlet Sourcecode:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDletStateChangeException;
/*
* Created on 26.05.2004
*
*/
/**
* @author Frank Kargl
*/
public class J2MEHelloWorld extends MIDlet implements CommandListener {
private Command exitCommand;
private Form form;
private Display display;
public J2MEHelloWorld() {
display = Display.getDisplay(this);
form = new Form("Test Midlet");
exitCommand = new Command("Exit", Command.EXIT, 2);
form.addCommand(exitCommand);
form.setCommandListener(this);
form.append("Platform: " + System.getProperty("microedition.platform")
+ "\n");
form.append("Configuration: "
+ System.getProperty("microedition.configuration") + "\n");
form.append("Profiles: " + System.getProperty("microedition.profiles")
+ "\n");
form.append("Encoding: " + System.getProperty("microedition.encoding")
+ "\n");
}
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(form);
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
notifyDestroyed();
}
}
}
Speichern und mit Run->RunAs->Emulated J2ME Midlet ausführen.