Java Reference
In-Depth Information
have space for soft buttons, but provide scrolling menus. MIDP needs to abstract from the concrete
device and to provide a mechanism that is suitable for all devices, independent of the availability and
number of soft buttons. Thus, the lcdui package does not provide buttons or menus, but an
abstraction called Command .
Command s can be added to all classes derived from the Displayable class. These classes are
Screen and its subclasses such as Form , List , and TextBox for the high-level API and Canvas
for the low-level API.
No positioning or layout information is passed to the Command —the Displayable class itself is
completely responsible for arranging the visible components corresponding to Command s on a
concrete device. The only layout and display information that can be assigned to a Command except
from the command label is semantic information. The semantic information consists of a type and a
priority. The priority allows the device to decide which commands are displayed as soft buttons if the
number of commands exceeds the number of soft buttons available. For additional commands not
displayed as soft buttons, a separate menu is created automatically. The type information is an
additional hint for the device about how to display the command. For example, if the Exit command is
always assigned to the leftmost soft button in native applications of a certain device type, the MIDP
implementation is able to make the same assignment. Thus, a consistent look and feel can be
accomplished for a device.
The available command type constants are listed in Table 3.5 .
Table 3.5. Command Type Constants
Constant Value
Command.BACK Used for navigation commands that are used to return the user to the
p revious Screen .
Command.CANCEL Needed to notify the screen that a negative answer occurred.
Command.EXIT Used to specify a Command for exiting the application.
Command.HELP Passed when the application requests a help screen.
Command.ITEM A command type to tell the application that it is appended to an explicit
i tem on the screen.
Command.OK Needed to notify the screen that a positive answer occurred.
Command.SCREEN A type that specifies a screen-specific Command of the application.
Command.STOP
I nterrupts a procedure that is currently running.
The Command constructor takes the label, the command type and the priority as input. The Command
class provides read() methods for all these fields, but it is not possible to change the parameters after
creation. Using the addCommand() method, commands can be added to a Form or any other
subclass of Displayable .
As in the case of receiving state changes of UI widgets, the MIDP uses a listener model for detecting
command actions. For this purpose, the lcdui package contains the interface CommandListener .
A CommandListener can be registered to any Displayable class using the
setCommandListener method. After registration, the method commandAction() of the
Commandlistener is invoked whenever the user issues a Command . In contrast to AWT, only one
listener is allowed for each Displayable class. The commandAction() callback method
provides the Displayable class where the command was issued and the corresponding Command
object as parameters.
With this information, you can extend your TeleTransfer application with the desired Command s.
But before going into actual command implementation, you need to add some corresponding
functionality. You'll add three commands: a Send command, a Clear command, and an Exit command.
For Clear, you just add a method setting the content of the fields of your form to empty strings:
 
Search WWH ::




Custom Search