The High-Level MIDP APIs

Now, let’s see how the various classes in the high-level API can be used to create GUI components. We will cover two parts of this process: working with screens and the components that subclass them, and working with forms and the components that can be arranged in them.

Working with Screens

Having seen an example of a screen, a few questions immediately come to mind: how do you manage screens, how do you navigate through them, and how do you manage the display and the input devices? The answer is that all this functionality is implemented by the Display class, which includes methods for requesting that objects be displayed on the device, and for retrieving properties of the device.

Display

A reference to the device’s display can be obtained by providing a MIDlet reference to the static getDisplay( ) method.

public static Display getDisplay(MIDlet c);

This is typically done in the startApp( ) method of a MIDlet, as follows:

public class MyMIDlet extends MIDlet {

   Display display = null;

   public MyMIDlet(  ) { // constructor
   }

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

   // other methods
}

Tip

The getDisplay( ) method should be called after the beginning of the MIDlet’s startApp( ) method, as shown earlier. It should never be called from the MIDlet’s constructor, as per the MIDP specification, as it may not be properly initialized by the application manager at that time.

After you obtain a reference to the device’s display, you simply need to ...

Get Wireless Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.