TOC PREV NEXT INDEX



Canvas


A Canvas is a free-form screen. Unlike the other screens, the Canvas may be used to paint graphics directly to the screen, and specific code can be written to handle key and pointer events. Canvases may also have Commands added to them.

Every Canvas has nine built-in nodes which cannot be recycled. They are

The paint method is very important for a Canvas, because all painting must be done in this method. The paint method should paint every pixel of the Canvas without assuming anything about the previous state of the screen, because the operating system may display dialogs (i.e. battery low, incoming phone call) which the MIDlet may not be aware of. The Code Sourcerer has options specifically for the paint method.

An example of a simple paint method for a canvas with an object name of canvas2 is

g.setColor(0,255,0);
g.fillRect(0,0,canvas2.getWidth(),canvas2.getHeight());
g.setColor(0,0,0);
g.drawString("Hello World",0,0,Graphics.LEFT|Graphics.TOP);

This code will draw a green background with black text of "Hello World". A more efficient paint routine might set the width and height of the canvas in the constructor code for the MIDlet.

Canvases do not have Titles or Ticker text associated with them.


Data Representations, Inc.
http://www.datarepresentations.com
support@datarepresentations.com
sales@datarepresentations.com
TOC PREV NEXT INDEX