モバイルのもと

スケルトンの作成

色々なちょっとしたテストコードを書くためにスケルトンのコードを作っておきます。(skelton.zip)

// File: applet.java

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

public final class applet extends MIDlet implements CommandListener {

  private static Command cmdExit = new Command("Exit", Command.EXIT,1);
  private static Display display;

  /* ----------------------------------------------------------------------*/
  public applet() {
    display = Display.getDisplay(this);
    mycanvas canvas = new mycanvas();

    canvas.addCommand(cmdExit);
    canvas.setCommandListener(this);

    display.setCurrent( canvas );
  }
  
  /* ----------------------------------------------------------------------*/
  public void startApp() {
  }

  /* ----------------------------------------------------------------------*/
  public void pauseApp() {
  }

  /* ----------------------------------------------------------------------*/
  public void destroyApp( boolean flag ) {
  }

  /* ----------------------------------------------------------------------*/
  public void commandAction(Command c, Displayable d) {
    try {
      destroyApp(true);
      notifyDestroyed();
    } catch ( Exception e) {}
  }
}

class mycanvas extends Canvas {
  mycanvas() {}
  
    public void paint( Graphics g ) {
    g.setColor( 255, 255, 255 );
    g.fillRect( 0, 0, getWidth(), getHeight() );

    g.setColor( 0, 0, 0 );
    g.drawString("This is Skelton app", 0, 0, Graphics.LEFT|Graphics.TOP);
  }

    public void keyPressed( int keycode ) {
        switch ( getGameAction( keycode ) ) {
      case FIRE:
        repaint();
        break;

      default:
        break;
    }
  }
}

モバイルの素へ戻る MIDP Scrollトップへ戻る


Google
MIDP2.0 CLDC1.1 JSR WWW

Copyright 2007 Mobile no THU