Java Reference
In-Depth Information
An Example
In this section, we'll show you StationSign , a CustomItem of medium complexity. StationSign
has the following features:
Implements a simple scrolling list of string choices. Pointer events and key events cause
the current selection to move to the next choice. The scrolling is animated. StationSign
is a Runnable —a separate thread is created in the constructor and used to call the run()
method. If there's a difference between the current display state of the item and the
current selection, run() reconciles the two by scrolling.
Conforms to the device's look and feel by using the font for static text and colors returned
from Display 's getColor() method.
Does not implement internal traversal.
•Uses the traverse() and traverseOut() methods to recognize focus and paint using
highlight colors. When traverse() is called, StationSign sets a boolean member variable,
mFocus , to indicate that the item has focus. In the paint() method, mFocus is used to
determine what colors are used to draw the item. When traverseOut() is called, mFocus
is set to false , indicating that focus has been lost.
The entire source code for StationSign is shown in Listing 7-3.
Listing 7-3. The StationSign Custom Item
import java.util.Vector;
import javax.microedition.lcdui.*;
public class StationSign
extends CustomItem
implements Runnable {
private Vector mValues;
private int mSelection;
private boolean mTrucking;
private Display mDisplay;
private Font mFont;
private int mVisibleIndexTimesTen;
private boolean mFocus;
public StationSign(String title, Display display) {
super(title);
mDisplay = display;
mValues = new Vector();
mSelection = 0;
mTrucking = true;
mFont = Font.getFont(Font.FONT_STATIC_TEXT);
mVisibleIndexTimesTen = mSelection * 10;
Search WWH ::




Custom Search