Java Reference
In-Depth Information
public void commandAction (Command c, Displayable d) {
if (c == exitCommand) {
notifyDestroyed();
}
else if (c == sendCommand) {
sendTransferInformation();
}
else if (c == clearCommand) {
resetTransferInformation();
}
else if (c == currencyCommand) {
display.setCurrent (currencyList);
}
else if (c == reasonCommand) {
display.setCurrent (transferReason);
}
}
}
Low-Level API
In contrast to the high-level API, the low-level API allows full control of the MID display at pixel level.
For this purpose, the lcdui package contains a special kind of screen called Canvas . The Canvas
itself does not provide any drawing methods, but it does provide a paint() callback method similar
to the paint() method in AWT components. Whenever the program manager determines that it is
necessary to draw the content of the screen, the paint() callback method of Canvas is called. The
only parameter of the paint() method is a Graphics object. In contrast to the lcdui high-level
classes, there are many parallels to AWT in the low-level API.
The Graphics object provides all the methods required for actually drawing the content of the screen,
such as drawLine() for drawing lines, fillRect() for drawing a filled rectangular area or
drawstring() for drawing text strings.
In contrast to AWT, lcdui does not let you mix high-level and low-level graphics. It is not possible to
display high-level and low-level components on the screen simultaneously.
The program manager knows that it must call the paint() method of Canvas when the instance of
Canvas is shown on the screen. However, a repaint can also be triggered by the application at any
time. By calling the repaint() method of Canvas , the system is notified that a repaint is necessary,
and it will call the paint() method. The call of the paint() method is not performed immediately;
it may be delayed until the control flow returns from the current event handling method. The system
may also collect several repaint requests before paint() is actually called. This delay normally is not
a problem, but when you're doing animation, the safest way to trigger repaints is to use
Display.callSerially() or to request the repaint from a separate Thread or TimerTask .
Alternatively, the application can force an immediate repaint by calling serviceRepaints() . (For
more information, see the section " Animation " at the end of this chapter.)
The Canvas class also provides some input callback methods that are called when the user presses or
releases a key or touches the screen with the stylus (if one is supported by the device).
Basic Drawing
Before we go into the details of user input or animation, we will start with a small drawing example
showing the concrete usage of the Canvas and Graphics classes.
 
Search WWH ::




Custom Search