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
- keyPressed A code area where Java code can be added which will be run when the Canvas detects a key being pressed.
- keyReleased A code area where Java code can be added which will be run when the Canvas detects a key being released.
- keyRepeated A code area where Java code can be added which will be run when the Canvas detects a key being held down. Note that a MID-enabled device might not have the ability to detect keyRepeated events.
- pointerDragged A code area where Java code can be added which will be run when the Canvas detects a pointer being dragged. Note that a MID-enabled device might not have a pointing device, or be able to detect pointer movement events.
- pointerPressed A code area where Java code can be added which will be run when the Canvas detects a pointer being pressed. Note that a MID-enabled device might not have a pointing device.
- pointerReleased A code area where Java code can be added which will be run when the Canvas detects a pointer being released. Note that a MID-enabled device might not have a pointing device.
- showNotify A code area where Java code can be added which will be run prior to the Canvas being made visible on the device.
- hideNotify A code area where Java code can be added which will be run after the Canvas has finished being displayed.
- paint A code area where Java code can be added which will draw the graphics for the Canvas.
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
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 |