Java Reference
In-Depth Information
CHAPTER 5
Building User Interfaces
T he CLDC brings together a number of flexible user-interface widgets from which you
can build many kinds of applications. Unlike other GUI platforms, the interfaces to these
UI widgets are highly abstracted, meaning you can write one application to run on a
number of different device configurations, such as those with keypads, touchscreens, or
even voice input. In fact, it's fair to say that the CLDC's generality has outstripped the
imagination of most device manufacturers; the interface to the widgets supports far more
kinds of hardware than have been commercially available.
In this day and age of drag-and-drop code generation to build user interfaces, it's
tempting to gloss over these details. After all, why worry too much about how forms col-
lect visible widgets when you can simply pick a specific form or widget from a palette and
then wire things together by pointing and clicking? Besides the obvious answer—you can
better design your application with a firm grasp of the fundamentals—understanding
these fundamentals enables you to create your own user-interface widgets, as well as effi-
ciently compose sophisticated applications that remain easy to navigate.
In this chapter, I show you the components you can use to build your application's
user interface. I begin by discussing the relationship between the various elements of
the javax.microedition.lcdui package and showing you how the various elements fit
together. I then discuss commands —the fundamental way users interact with your
application. After that, I give you a comprehensive introduction to the various visible
objects you can create, beginning with simple items for showing text and choices, and
moving on to how you group these items into application screens. Finally, I discuss
how these items interact with the display canvas so that you can understand how to
make your own visible objects.
Understanding the Relationship Between the
Display and Visible Item Objects
The ultimate purpose of MIDlets is to interact with the user. In a very real sense, your
MIDlet's flow can be reduced to the following process: pick a Displayable to show, set the
Display to show the Displayable , wait for a Command , and then pick the next Displayable (or
exit). The state machine diagram in Figure 5-1 shows this process.
97
 
Search WWH ::




Custom Search