Creating a Command
When creating a new Command object to hold event information, there are three parameters: label, type, and priority. Let's look at each parameter in detail.
cmdHelp = new Command("Help", Command.HELP, 1); | | | label type priority
labelThis specifies the text that you would like to associate with the command. The label may be shown directly on the screen or displayed inside a menu.
Figures 1 shows a command with the label Exit. The command is mapped to the soft button shown directly below the label.
Figure 2 shows two commands, with the labels Upload and Download, placed inside a menu.
typeIf at all possible, we'd like to directly map commands to relevant soft buttons on a device. For example, if a device has a soft button labeled Help, it would be very intuitive for the user to have a command mapped to that soft button to display a help message (see Figure 3). We specify our intent to map a command to a specific soft button using this parameter. The available types for this parameter are shown in Table 1.
priorityIn relation to other commands you define, this value represents where this command falls in the line of priority. The higher the number is, the lower the priority is. These values are helpful for the application manager when arranging items that appear in a menu or for ordering soft buttons on the display. In an example to follow, we'll specify the priority of two commands to request the order we would like the commands presented in a menu.
Figure 1 Exit command mapped to a soft button.
Figure 2 Upload and Download commands available in a menu.
Figure 3 This device has a soft button specifically intended to display help.
Table 1 Command Types: javax.microedition.lcdui.Command
Value
Description
BACK
A request to move to the previous screen
CANCEL
A request to cancel an operation
EXIT
A request to exit the MIDlet
HELP
A request to display help information
ITEM
A request to map the Command to an "item" on the screen
OK
Specify positive acknowledgement from a user
SCREEN
Apply to the screen as a whole, such as Save
STOP
A request to stop an operation