Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Take the High Road when Creating MIDP User Interfaces : Page 4

MIDP supports a user interface framework that caters to mobile devices by providing a number of built-in controls. Find out how these controls enable the portability of applications between devices.


advertisement
Event Handling
The high-level MIDP 2.0 controls provide three ways to respond to user interactions. The most common is to create a Command. Commands 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. Commands are available to any Displayable. When the Displayable is the current display, all issued Commands are directed to the CommandListener registered with the Displayable. CommandListener 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.



David Hemphill is the Lead Architect at Gearworks, a Minn.-based company that specializes in wireless workforce automation. He is also the co-author of "Java 2 Micro Edition" (Manning). David is also a member of the Sun-Certified J2ME Exam expert group.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date