extends Canvas to create your own drawable area : Canvas « J2ME « Java Tutorial






extends Canvas to create your own drawable area
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

public class CanvasMyMidlet extends MIDlet {
  public CanvasMyMidlet() { // constructor
  }

  public void startApp() {
    Canvas canvas = new MyCanvas();
    Display display = Display.getDisplay(this);
    display.setCurrent(canvas);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }
}

class MyCanvas extends Canvas {
  public void paint(Graphics g) {
    g.setColor(255, 0, 0);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(255, 255, 255);
    g.drawString("Hello World!", 0, 0, g.TOP | g.LEFT);
  }
}








31.24.Canvas
31.24.1.extends Canvas to create your own drawable areaextends Canvas to create your own drawable area
31.24.2.Get Canvas propertiesGet Canvas properties
31.24.3.Canvas key pressed and key typed events
31.24.4.Use Canvas to draw a clockUse Canvas to draw a clock
31.24.5.Canvas sizeCanvas size
31.24.6.Navigatable Canvas
31.24.7.Canvas key event and navigate through arrow keys