Login | Register   
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
 

Java ME User Interfaces: Do It with LWUIT! : Page 3

Java ME user interfaces are about to get an exciting boost with the early release of a new library and tool from Sun called LWUIT.


advertisement

A Simple LWUIT Application
Using LWUIT is about as easy as it is to set up. First, from inside of the MIDlet (the startApp() method for example), initialize LWUIT.


Display.init()

The Display class manages LWUIT rendering and handles events. It is also used to place top level components, called forms, on the screen. Forms are created with simple constructors and then "shown" on the display.




Form myform = new Form();
myform.show();

Between the Form creation and showing, it's a matter of creating, configuring, and adding user interface widgets (text box, button, and so on) to the Form:

Figure 3. The Application Launch Screen: LWUIT themes, use of resource files, layout management, and clean widgets can make a MIDlet form like this initial application page look like an application selector.


Form myform = new Form();
Button myButton = new Button("Push me");
myform.addComponent(myButton);
myform.show();

It's that easy. For a more in depth example, this article's sample application demonstrates some of the power and functionality in LWUIT. It's a simple application consisting of a single MIDlet (see Listing 1) that allows student data to be collected and displayed on a mobile device.

 

The first screen of the application allows the user to select from a set of "virtual" applications by selecting from what looks like a set of icons. In this screen, one can also see how the use of resource files and "themeing" (a concept discussed later in this article) applies background images and a general look and feel to the application (see Figure 3). Using a simple image scaling mechanism, the buttons with images that serve as icons can even be made to look as if they are being depressed.

From the main application selection screen, a user can select a student record for editing from a LWUIT List widget and use LWUIT buttons to remove or add a student (see Figure 4).


Figure 4. LWUIT List and Buttons: The List widget conveniently displays any array or Vector of objects.
 
Figure 5. Data Entry with LWUIT: The List widget set is more comprehensive that MIDP’s LCDUI and control and display of the widgets are also more in the developers' hands.

The student editing screen shows many common widgets available in LWUIT (TextArea, ComboBox, Calendar, and so on) that are familiar to Swing developers. The editing screen also makes extensive use of LWUIT Layout Managers to provide a user interface that almost looks desktop-like in nature. Figure 5 shows the List widget set, which is more comprehensive that MIDP's LCDUI. It also places the control and display of the widgets more in developers' hands.

 



Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap