Pacer : 2D « J2ME « Java






Pacer

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

public class Pacer extends MIDlet{ 
  public void startApp() { 
    Displayable d = new PacerCanvas();
    
    d.addCommand(new Command("Exit", Command.EXIT, 0));
    d.setCommandListener(new CommandListener() { 
      public void commandAction(Command c, Displayable s) { 
        notifyDestroyed();
      } 
    } );
    
    Display.getDisplay(this).setCurrent(d);
  } 
  
  public void pauseApp() { } 

  public void destroyApp(boolean unconditional) { } 
} 

class PacerCanvas extends Canvas { 
  public void paint(Graphics g) { 
    int w = getWidth();
    int h = getHeight();
    
    g.setColor(0xffffff);
    g.fillRect(0, 0, w, h);
    g.setColor(0x000000);

    for (int x = 0; x < w; x += 10)
      g.drawLine(0, w - x, x, 0);
    
    int z = 50;
    g.drawRect(z, z, 20, 20);
    z += 20;
    g.fillRoundRect(z, z, 20, 20, 5, 5);
    z += 20;
    g.drawArc(z, z, 20, 20, 0, 360);
  } 
} 

           
       








Related examples in the same category

1.Simple Midlet DemoSimple Midlet Demo
2.Piano MIDletPiano MIDlet
3.Pointer ExamplePointer Example
4.Text Example
5.Simple Canvas
6.Illustrate Graphics MIDletIllustrate Graphics MIDlet
7.Translate CoordinatesTranslate Coordinates
8.Key Canvas
9.Box Text CanvasBox Text Canvas
10.Offscreen MIDletOffscreen MIDlet
11.Quatsch MIDletQuatsch MIDlet
12.Sweep GameSweep Game
13.SweepSweep
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.