Canvas
class is the main template for low-level MIDlet graphics.
Being a low-level API, Canvas
offers
more options to customize a MIDlet but the MIDlet won't be as portable as
ones created using only high-level APIs. In contrast to the high-level classes
mentioned above, Canvas
enables MIDlet programmers to
draw any graphics on the screen. The MIDlet can use any drawing primitives
provided by the LCDUI Graphics
interface.
A common example of a MIDlet that uses Canvas
is
a mobile game that requires pixel-accurate drawing and access to low-level
keypad events. At least two simultaneous key presses are supported in Canvas
Displayable
.
Canvas
is a subclass of Displayable
,
and applications can attach Commands
to it. This is useful
for implementing high-level actions to a MIDlet. The Canvas
methods hideNotify()
and showNotify()
is called to indicate when the Canvas
has been obscured
and unobscured, respectively.
The Canvas
class has a full screen mode, where
the whole display area is available to the MIDlet. The full screen mode can
be activated/deactivated by the application by calling the setFullScreenMode
function.
In MIDP, a virtual machine is able to trigger various events on Canvas
,
such as key presses, releases, repeats, and whether Canvas
is
still visible or not.
For more information on Canvas
, see Canvas
implementation notes.
For an example of using Canvas
, see section Example: Creating a simple
test MIDlet.