#ff0000 12  2005 . - #000655    .  1
#000655  MIDlet
#0000ff  Carol Hamer
#def   MIDP 2.0 API            . ,             . ,       MIDP 1.0 (Atair 2600   ),       ,    ,      . MIDP 2.0             PC.             .         Super Mario Brothers  Alladin.
       MIDlet- (Maidlet -   ,      ).  ,     Java,      J2ME.  
,    ?   .   ,    ,   -. ,    ,        ,       .
      . http://www.microdevnet.com/articles/resources.zip
!
      J2ME,     .  http://java.sun.com/j2me/download.html. Java 2 Micro Edition Wireless Toolkit       MIDlet-,   ,    .       .       .
     ,  ,      : *.jad  *.jar. Jar  -  ,     , ,  . Jad  ( )   ,     MIDlet.  Jad        URL jar  MIDlet-.    jad  Hello World :
MIDlet-1: Hello World, /icons/hello.png, net.frog_parrot.hello.Hello
MMIDlet-Description: Hello World for MIDP
MIDlet-Jar-URL: hello.jar
MIDlet-Name: Hello World
MIDlet-Permissions: 
MIDlet-Vendor: frog-parrot.net
MIDlet-Version: 2.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
MIDlet-Jar-Size: 3201
 MIDlet-1 ( MIDlet-2,  ..)   MIDlet-,   ,    ,    .      MIDlet    MIDlet-.     jar ,        ,    Class.getResource().    jar   icons,     hello.png.    :
 MIDlet-Jar-Size   jar    .  ,         ,  build ,         jar   .  MIDlet-Jar-Size  jad     jar , MIDlet  . ( ,      jad ,    ,       .)  MIDlet-Jar-URL   jar  MIDlet-   jad .        ,       jad .         .
Hello World 
    MIDlet-      "Hello World" . MIDlet      "Hello World!"        "Toggle Msg" .   "Exit"    MIDlet-.     : MIDlet  Hello  Canvas  HelloCanvas.     ,      .
*******************   Hello.java ************************
package net.frog_parrot.hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 *     .
 *
 * @ Carol Hamer
 */
public class Hello extends MIDlet implements CommandListener {

  /**
   * Canvas -   ,    .
   */
  HelloCanvas myCanvas;

  /**
   * Command - ,  .
   */
  private Command exitCommand = new Command("Exit", Command.EXIT, 99);

  /**
   * Command - ,  .
   */
  private Command newCommand = new Command("Toggle Msg", Command.SCREEN, 1);

  /**
   *  canvas  commands.
   */
  public Hello() {
    myCanvas = new HelloCanvas(Display.getDisplay(this));
    myCanvas.addCommand(exitCommand);
    myCanvas.addCommand(newCommand);
    myCanvas.setCommandListener(this);
  }

  //----------------------------------------------------------------
  //    MIDlet-

  /**
   *  .
   */
  public void startApp() throws MIDletStateChangeException {
    myCanvas.start();
  }
  
  /**
   *  MIDlet  ,    
   *      .
   */
  public void destroyApp(boolean unconditional) 
      throws MIDletStateChangeException {
  }

  /**
   *   ,   MIDlet  
   *   . MIDlet     
   *   .
   */
  public void pauseApp() {
  }

  //----------------------------------------------------------------
  //     CommandListener

  /*
   *     (  ).
   */
  public void commandAction(Command c, Displayable s) {
    if(c == newCommand) {
      myCanvas.newHello();
    } else if(c == exitCommand) {
      try {
 destroyApp(false);
 notifyDestroyed();
      } catch (MIDletStateChangeException ex) {
      }
    }
  }
  
}
****************   HelloCanvas.java ********************
package net.frog_parrot.hello;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 *     ,    .
 * @ Carol Hamer
 */
public class HelloCanvas extends javax.microedition.lcdui.game.GameCanvas {

  //---------------------------------------------------------
  //   

  /**
   *    
   */
  Display myDisplay;

  /**
   *        .
   */
  boolean mySayHello = true;

  //-----------------------------------------------------
  //        

  /**
   *    .
   */
  public HelloCanvas(Display d) {
    super(false);
    myDisplay = d;
  }

  /**
   *  .
   */
  void start() {
    myDisplay.setCurrent(this);
    repaint();
  }

  /**
   * 
   *    .
   */
  void newHello() {
    mySayHello = !mySayHello;
    //  .
    repaint();
  }

  //-------------------------------------------------------
  //   

  /**
   *       .
   */
  public void paint(Graphics g) {
    // x  y -      .
    int x = g.getClipX();
    int y = g.getClipY();
    // w  h     .
    int w = g.getClipWidth();
    int h = g.getClipHeight();
    //   ( ).
    g.setColor(0xffffff);
    g.fillRect(x, y, w, h);
    //  ,  .
    if(mySayHello) {
      Font font = g.getFont();
      int fontHeight = font.getHeight();
      int fontWidth = font.stringWidth("Hello World!");
      //     .
      g.setColor(0x00ff0000);
      g.setFont(font);
      //     .
      g.drawString("Hello World!", (w - fontWidth)/2, 
     (h - fontHeight)/2,
     g.TOP|g.LEFT);
    }
  }

}
#0000ff : Alex. #ff0000          :  http://www.mobilab.ru