Canvas

Description:

The following code shows a Canvas example.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Canvas_Example extends MIDlet
{
    Display display=Display.getDisplay(this);
    public void startApp()
    {
        CanvasDemo canvas = new CanvasDemo();
        display.setCurrent(canvas);
    }
}
class CanvasDemo extends Canvas
{
  public void paint (Graphics g)
  {
    g.setColor(50,50,255);
    g.fillRect (0, 0, getWidth (), getHeight ());
    g.setColor(200,200,200);
    g.drawString("Example of Canvas",0,20,0);
    g.setColor(0,0,100);
    g.drawLine (0, 40, 100, 200);
    g.setColor(200,0,0);
    g.fillRect (50, 70, 80, 50);
  }
}

Download:

Canvas.java

Output:

The following screenshots are the outcome. Just click on the icon to enlarge it for a better view.

Department of Electronic Systems | Aalborg University | Niels Jernes Vej 12 | DK-9220 Aalborg | Denmark
Phone: (+45) 9635 8695 | Fax (+45) 9815 1583 | E-mail ies(at)ies.aau.dk
Copyright © 2006 Department of Electronic Systems

Last update:11-10-2006