
J2ME
Überblick
J2ME ist die Api, welche einem ermöglicht Javaprogramme für Mobiltelefone(Handys) zu schreiben. Es gibt inzwischen diverse Erweiterungen, welche es ganz spannend machen, sich damit mal näher zu befassen. Aber zum Glück wird man sich nicht lange mit java abmühen müssen. Es gibt wohl bald einen jython Port für die J2ME/CVM.
Beispiel
Wichtig ist ein package anzulegen, da man sonst folgenden Fehler erhält:
java.lang.SecurityException: Application not authorized to access the restricted API
Und hier das Beispiel:
-
package helloworld;
-
-
import javax.microedition.midlet.*;
-
import javax.microedition.lcdui.*;
-
-
-
public class HelloWorld extends MIDlet implements ItemCommandListener {
-
private static final Command CMD_PRESS = new Command("Gedrueckt", Command.ITEM, 1);
-
-
private Display display;
-
private Form mainForm;
-
-
protected void startApp() throws MIDletStateChangeException{
-
mainForm = new Form("Form: Hallo Welt");
-
display = Display.getDisplay(this);
-
-
mainForm.append("Hallo Welt!");
-
-
StringItem item = new StringItem("Dies ist ein Label: ", "Dies ist der Text");
-
mainForm.append(item);
-
-
item = new StringItem("Knopp", "Knopp", Item.BUTTON);
-
item.setDefaultCommand(CMD_PRESS);
-
item.setItemCommandListener(this);
-
mainForm.append(item);
-
-
display.setCurrent(mainForm);
-
}
-
-
public void commandAction(Command c, Item item) {
-
if (c == CMD_PRESS) {
-
String text = "Mach man Aktion
"; -
Alert a = new Alert("Action", text, null, AlertType.INFO);
-
display.setCurrent(a);
-
}
-
}
-
-
protected void destroyApp(boolean unconditional) {
-
}
-
-
protected void pauseApp() {
-
}
-
}
Links
Eine andere Hallo Welt Seite.
Die J2ME hier herunterladen. Man braucht eigentlich nur das Sun Java Wireless Toolkit 2.5.2 for CLDC.
Jython auf CVM.


























on März 25th, 2008 at 01:00
[...] (via Live Search: j2me blog) [...]