The high-level MIDP 2.0 controls provide three ways to respond to user interactions. The most common is to create a Command
generally display a label above one of the device softkeys. When the user presses the softkey, an event is fired and the application can respond appropriately.
are available to any Displayable
. When the Displayable
is the current display, all issued Commands
are directed to the CommandListener
registered with the Displayable
is an interface supporting the event handler method commandAction()
. To set the CommandListener
make a call to Displayable.setCommandListener()
. There can be only one CommandListener
for a Displayable
at any given time.
If the application uses a Form, state changes can be monitored on an Item-by-Item basis using the ItemStateListener. When the user modifies an Item, a call to ItemStateListener.itemStateChanged() is made. The Item of interest is passed as a parameter. An ItemStateListener is registered with the Form and will be notified if any Items on the Form are changed.
As of MIDP 2.0, Forms have another method of interacting with users through the implementation of ItemCommandListener. Like CommandListener, ItemCommandListener defines a commandAction() method. The difference is that the ItemCommandListener is registered with the Item itself, rather than with the Form. This localizes the Command event response to the Item rather than making the Form handle event logic for all Items.
Finally! Portable UI Made Easy
Creating user interfaces that can be deployed to multiple devices without modification is a challenge for mobile software developers. The MIDP specification contains user interface APIs designed to address many portability issues. To take advantage of the designed-in portability of MIDP, developers are encouraged to use the high-level APIs whenever possible and practical.
The high-level APIs provide many out-of-the-box user interface features as well as help ensure the application user interface maps correctly from device to device. In some cases, however, the high-level APIs may be too limiting to provide the desired effect or capability needed by an application. These situations may call for using the low-level APIs. In next month's article I will discuss using the low-level APIs and highlight some of the implementation trade-offs, benefits, and issues developers are likely to encounter.