Using Display

Team-Fly

There's not much to say about Display, which manages a device's screen. You can get a reference to the device's display by supplying a MIDlet reference to the static getDisplay() method. Typically, you'll do this in the or startApp() method of a MIDlet:

 public void startApp() {   Display d = Display.getDisplay(this);   // ... } 

You may be tempted to call getDisplay() in a MIDlet's constructor, but according to the documentation, getDisplay() can only be called after the beginning of the MIDlet's startApp() method.

Once you've got a reference to a device's Display, you'll just need to create something to show (an instance of Displayable) and pass it to one of Display's setCurrent() methods:

 public void setCurrent(Displayable next) public void setCurrent(Alert alert, Displayable nextDisplayable) 

The second version is used when you want to show a temporary message (an Alert) followed by something else. I'll talk more about Alerts at the end of this chapter.

Display's getCurrent() method returns a reference to what's currently being shown.

Finally, you can query a Display to determine what kind of color support it has. The numColors() method returns the number of distinct colors supported by this device, while the isColor() method tells whether the device supports color or grayscale. A Display for a device supporting 16 levels of gray, for example, would return false from isColor() and 16 from numColors().


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net