Command is a useful item in every application. It tells the program to perform a specific action when the user choose to do so. In other words, the command increases the users' interactivity with your software. A command object can be created by using the following prototype:
Command commadObj=new Command(Label,Type,Priority);
Label is the text to display on the command button. The Type argument specifies the type of command. The values of the Type argument can be Command.BACK, Command.CANCEL, Command.EXIT, Command.HELP, Command.ITEM, Command.OK, Command.SREEN, and Command.STOP. The Priority sets the priority of the command. If the value is 0, it is the highest priority command. The higher the value the lower the priority is.
The command can be attached to the form by using addCommand method of the form. To enable the form to listen to the actions that will perform by the user, you need to set the CommandListener interface to the form by using setCommandListener method.
Form form=new Form("Form");
The this keyword refers to the current CommandListener interface that the class is currently implemented. This interface has a special method named commandAction. In this method you can write code to response to the command action. In the example code below, when the user clicks on Cancel command the program will exit and the memory use is released. By clicking on the Ok command the program will call the check method and alert whether the user id and password are correct or incorrect.
Note: to read the value of a text field
you can use getString() method of the text field object. If you want to
write text programmatically to the text field you need to use setString(text