To create an IconCommand
:
IconCommand
object. Use the constructor
parameters to define the icon image, labels, command type, and priority.IconCommand okcommand; IconCommand screencommand; //Image provided to represent selected icon img = Image.createImage("/image/selected.png"); //Image provided to represent unselected icon unselected_img = Image.createImage("/image/unselected.png"); //Create the IconCommand using system icon ID. //Parameters defined are: short label=OK, long label=OK, commandType=4 (Type OK), priority=1, iconId=1 (which is ICON_BACK) okcommand = new IconCommand("OK", "okay", 4, 1, 4); //Create the IconCommand using midlet defined images. //Parameters defined are: short label=Screen, long label=screen command, commandType=1 (Type SCREEN), priority=2 screencommand = new IconCommand("Screen", "screen command", unselected_img, img, 1, 2);
Define the action
for the IconCommand
by using a CommandListener
. Like a Command
, an IconCommand
only encapsulates the semantic
information for an action, not the actual action, so you need to implement
the action separately through a CommandListener
.
For detailed information about the IconCommand
constructors and built-in system icon IDs, see the IconCommand
class reference.