ColdFusion MX Professional Projects

Team-Fly

The MIDP contains user-interface classes in the javax.microedition.lcdui package. The MID's display is represented by an instance of the Display class, accessed from a factory method, getDisplay(). Display's main purpose in life is to keep track of what is currently shown, which is an instance of Displayable. If you think of Display as an easel, a Displayable instance is akin to a canvas on that easel.

MIDlets can change the contents of the display by passing Displayable instances to Display's setCurrent() method. This is the basis of a typical MIDlet:

  1. Show a Displayable.

  2. Wait for input.

  3. Decide what Displayable should be next.

  4. Repeat.

Displayable has a small family of subclasses that represent various types of user interfaces. Figure 5-1 shows the lineage.

Figure 5-1: Displayables in the javax.microedition.lcdui package

Displayable's progeny are split between two branches that correspond to the two methods for creating generalized user interfaces, abstraction and discovery. Screen represents displays that are specified in abstract terms. These screens contain standard user-interface items like combo boxes, lists, menus, and buttons. Four subclasses provide a wide range of functionality, as illustrated in Figure 5-2.

Figure 5-2: The four children of Screen: (a) TextBox, (b) Alert, (c) List, and (d) Form

The remainder of this chapter is devoted to explaining the simplest of these four classes, TextBox and Alert. The next chapter explores the more flexible List and Form.

For particularly demanding or idiosyncratic displays, you'll have to create a subclass of Canvas. Your MIDlet will assume responsibility for most of the drawing, but you get much finer control over what is shown and how user input is handled. Canvas supplies methods that allow your MIDlet to learn about its environment-the size of the display, for example, and which kinds of events are supported by the device. User interfaces built on Canvas discover the attributes of a device and attempt to create something that looks reasonable. Chapter 9 explains Canvas-based user interfaces in detail.


Team-Fly

Категории