Offscreen MIDlet : 2D « J2ME « Java

Offscreen MIDlet

Offscreen MIDlet
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

public class OffscreenMIDlet extends MIDlet {
  public void startApp() {
    Displayable d = new OffscreenCanvas();

    d.addCommand(new Command("Exit", Command.EXIT, 0));
    d.setCommandListener(new CommandListener() {
      public void commandAction(Command c, Displayable s) {


  public void pauseApp() {

  public void destroyApp(boolean unconditional) {

class OffscreenCanvas extends Canvas {
  private Image mImage;

  public void paint(Graphics g) {
    if (mImage == null)
    g.drawImage(mImage, 0, 0, Graphics.TOP | Graphics.LEFT);

  private void initialize() {
    int w = getWidth();
    int h = getHeight();

    mImage = Image.createImage(w, h);

    Graphics g = mImage.getGraphics();

    g.drawRect(0, 0, w - 1, h - 1);
    g.drawLine(0, 0, w - 1, h - 1);
    g.drawLine(w - 1, 0, 0, h - 1);


Related examples in the same category

1.Simple Midlet DemoSimple Midlet Demo
2.Piano MIDletPiano MIDlet
4.Pointer ExamplePointer Example
5.Text Example
6.Simple Canvas
7.Illustrate Graphics MIDletIllustrate Graphics MIDlet
8.Translate CoordinatesTranslate Coordinates
9.Key Canvas
10.Box Text CanvasBox Text Canvas
11.Quatsch MIDletQuatsch MIDlet
12.Sweep GameSweep Game
14.Text MIDletText MIDlet
15.Translate coordinate systemTranslate coordinate system
16.Show various anchor pointsShow various anchor points
17.Draw mutable image on a canvas
18.Canvas for processing key code and commandsCanvas for processing key code and commands
19.Draw immutable image on a canvasDraw immutable image on a canvas
20.Use pointer events to draw onto the CanvasUse pointer events to draw onto the Canvas
21.A quick sample of graphics, commands, and event handling.A quick sample of graphics,  commands, and event handling.