Java Reference
In-Depth Information
public void addCommand(Command cmd)
public void removeCommand(Command cmd)
Creating Commands
In MIDP, commands are represented by instances of the Command class. To create a Command , just
supply a name, a type, and a priority. The name is usually shown on the screen. The type can
be used to signify a commonly used command. It must be one of the values defined in the
Command class. Table 5-1 shows the type values and their meanings.
Table 5-1. Command Types
Name
Meaning
OK
Confirms a selection
CANCEL
Cancels pending changes
BACK
Moves the user back to a previous screen
STOP
Stops a running operation
HELP
Shows application instructions
SCREEN
Indicates generic type for specific application commands
To create a standard OK command, for example, you would do this:
Command c = new Command("OK", Command.OK, 0);
To create a command specific to your application, you might do this:
Command c = new Command("Launch", Command.SCREEN, 0);
It's up to the MIDP implementation to figure out how to show the commands. In the Sun
J2ME Wireless Toolkit emulator, commands are assigned to the two soft buttons. A soft button
is a button on the device keypad with no predefined function. A soft button can serve a different
purpose at different times. If there are more commands than there are soft buttons, the commands
that don't fit will be grouped into a menu that is assigned to one of the soft buttons.
A simple priority scheme determines who wins when there are more commands than
available screen space. Every command has a priority that indicates how hard the display
system should try to show the command. Lower numbers indicate a higher priority. If you add
a command with priority 0, then several more with priority 1, the priority 0 command will show
up on the screen directly. The other commands will most likely end up in a secondary menu.
Long labels are supported on commands. The actual MIDP implementation decides
which label it will use based on the available screen space and the size of the labels. You can
create a command with a short and long label like this:
Command c = new Command("Run", "Run simulation", Command.SCREEN, 0);
The Command class provides getLabel() , getLongLabel() , and getCommandType() methods
for retrieving information about commands.
 
Search WWH ::




Custom Search