Java Reference
In-Depth Information
Using Commands to Control Application Flow
Traditional user-interface programming requires implementation based on either
event-handling or MVC paradigms (or a combination thereof ). The MIDP takes an
approach similar to the former paradigm, defining the Command class to encapsulate the
notion of a command from the user to the application. The MIDP environment sends
instances of the Command class to registered listeners, much as the Java AWT sends
events to event listeners. To receive instances of the Command class, MIDP objects must
implement the CommandListener interface, providing a commandAction method. Each
Command instance is added to a Displayable instance, which is responsible for presenting
the command to the user in some way (such as via a soft key or menu). The Displayable
instance is also responsible for sending the instance to a registered listener when you
activate the command.
Instances of Command are tuples, consisting of a short label, a long label, a type, and
a priority:
Labels : Labels specify what the command shows on the user interface; only one
label is required. Where the label—and which label—for a command actually
appears in the user interface depends on several things, including the priority
of the command, the implementation of the Displayable to which you add the
command, and the implementation of the MIDP runtime itself. (Figure 5-3 shows
an example of commands in a soft key menu.)
Type : The type indicates the kind of command, both for your application logic and
potentially for the UI of the MIDP runtime. It presents additional information
(such as an icon) about the command.
Priority : The priority indicates the relative importance of the command to the user
interface. The lower the priority, the more obvious the command's placement on
the Displayable to which it's assigned.
 
Search WWH ::




Custom Search