J2ME

Veröffentlicht am 17. Dezember 2007 in von muhgatus

Ü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:

  1. package helloworld;
  2.  
  3. import javax.microedition.midlet.*;
  4. import javax.microedition.lcdui.*;
  5.  
  6.  
  7. public class HelloWorld extends MIDlet implements ItemCommandListener {
  8.         private static final Command CMD_PRESS = new Command("Gedrueckt", Command.ITEM, 1);
  9.  
  10.   private Display display;
  11.   private Form mainForm;
  12.  
  13.   protected void startApp() throws MIDletStateChangeException{
  14.     mainForm = new Form("Form: Hallo Welt");
  15.     display = Display.getDisplay(this);
  16.  
  17.     mainForm.append("Hallo Welt!");
  18.  
  19.     StringItem item = new StringItem("Dies ist ein Label: ", "Dies ist der Text");
  20.     mainForm.append(item);
  21.  
  22.     item = new StringItem("Knopp", "Knopp", Item.BUTTON);
  23.     item.setDefaultCommand(CMD_PRESS);
  24.     item.setItemCommandListener(this);
  25.     mainForm.append(item);
  26.  
  27.     display.setCurrent(mainForm);
  28.   }
  29.  
  30.   public void commandAction(Command c, Item item) {
  31.     if (c == CMD_PRESS) {
  32.       String text = "Mach man Aktion ;) ";
  33.       Alert a = new Alert("Action", text, null, AlertType.INFO);
  34.       display.setCurrent(a);
  35.     }
  36.   }
  37.  
  38.   protected void destroyApp(boolean unconditional) {
  39.   }
  40.        
  41.   protected void pauseApp() {
  42.   }
  43. }

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.

QR Code for J2ME

One Response to 'J2ME'

Subscribe to comments with RSS or TrackBack to 'J2ME'.


  1. on März 25th, 2008 at 01:00

    [...] (via Live Search: j2me blog) [...]

Post a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word