// GraphicsDemoMIDlet.java (c) Kari Laitinen // http://www.naturalprogramming.com // 2006-03-09 File created. // 2007-09-02 Last modification. // See notes at the end of this file. import javax.microedition.midlet.*; import javax.microedition.lcdui.*; class GraphicsDemoCanvas extends Canvas { int canvas_width = getWidth() ; int canvas_height = getHeight() ; public void paint( Graphics graphics ) { graphics.setColor( 255, 255, 255 ) ; // white color clears the canvas graphics.fillRect( 0, 0, canvas_width, canvas_height ) ; graphics.setColor( 0, 0, 0 ) ; // black color is used for drawing graphics.drawString( "Canvas size is " + canvas_width + " x " + canvas_height, 20, 20, Graphics.TOP | Graphics.LEFT ) ; // Drawing a horizontal line into the middle of canvas area. graphics.drawLine( 0, canvas_height / 2, canvas_width, canvas_height / 2 ) ; graphics.fillRect( 20, 70, 100, 40 ) ; graphics.fillArc( 20, 170, 100, 80, 45, 270 ) ; graphics.drawArc( 100, 170, 100, 80, 315, 90 ) ; } } public class GraphicsDemoMIDlet extends MIDlet { Display display_of_this_midlet = Display.getDisplay( this ) ; GraphicsDemoCanvas canvas_of_this_midlet = new GraphicsDemoCanvas() ; protected void startApp() throws MIDletStateChangeException { display_of_this_midlet.setCurrent( canvas_of_this_midlet ) ; } protected void pauseApp() { } protected void destroyApp( boolean unconditional_destruction_required ) { } } /* NOTES: The GraphicsDemoCanvas class could alternatively be written with a constructor in the following way: class GraphicsDemoCanvas extends Canvas { int canvas_width, canvas_height ; public GraphicsDemoCanvas() { canvas_width = getWidth() ; canvas_height = getHeight() ; } ... */