RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


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

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.


Significant Features (cont'd)

A Painter is an interface that allows you to implement code that draws on a Component's background within the bounds of the Component's area. A Painter interface requires the paint method to be provided that draws inside the desired image inside the components rectangular clipped area. A Painter object is then used through a Component's Style object. As an example, the code in Listing 6 provides a reusable painter that puts a red box around a Component (see Figure 12); perhaps to highlight a potentially "dangerous" user option. Once coded, the Painter can be set as the background painter on any Component's Style object (see Listing 7).

Figure 12. Highlighting a Button with a Painter: Painters allow custom drawing to be done on a Component via its Style object as shown by painting a red box around this Button.
Figure 13. Example Transitions: Transitions allow the change between Form objects to take on flair. The examples above show the change between two forms caught in mid-transition using slide, fade, and 3D rotate transitions.

To spice up those Java ME user interfaces, you might also want to consider using a bit of animation. No, not the dancing Duke type of animation (although LWUIT can help you do that too), but adding animation that helps provide a visual indicator to the user when the form or page changes. In LWUIT, changes between Forms can be made more visually acute with the addition of a transition. This feature is not unlike setting up animation between slides in PowerPoint. There are several types or modes of transition: slide, fade, and 3D transitions. A slide transition allows one form to replace the existing form display by moving in from either the left, right, top or bottom. A fade transition causes one form to gradual fade away while displaying the second form. On devices that support the Mobile 3D Graphics API, additional 3D transitions are possible (fly in, cube rotation as shown in Figure 13, flip rotation). A LWUIT transition class allows animation to simply be added to a form (either as a transition into the form or out of the form). In the example shown below, a slide out transition is set from the first form of the sample application to the student list form. The parameter false indicates the transition should occur left to right (versus right to left), and the parameter 1000 is the time it should take to complete the transition to the next form (in milliseconds):

(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));

To set up a fade transition, call on createFade instead of createSlide on the CommonTransitions class:


As an example of using a 3D transition, use the Transition3D class and call the createRotation() method to have the current form appear as if it is flipped over to the next form:

iconForm.setTransitionOutAnimator(Transition3D.createRotation(1000, true));

Logging is a basic need in any application. As it is not available in many Java ME environments, developers have had to roll their own into their applications. As a surprising bonus, the LWUIT library offers a simple logging framework. The logging framework allows developers to log to the Java ME record management system (RMS) storage or the file system. The Log class and static p methods allow developers to write to the log, wherever it is:

Log.p(“I am in here”);

Common to most logging frameworks there are four log levels available: Debug, Info, Error, and Warning.

But Wait, There's More!
Again, there is not enough space to cover all of LWUIT's capabilities. In addition to the features shown here, what other features might you want to research? Here are a few others:

  • Built in support for touch screens
  • Built in support for Mobile 3D Graphics (M3G) API for J2ME
  • Localization/Internationalization support

LWUIT Documentation
Unlike many early release projects, LWUIT comes with a pretty good set of documentation. The Javadoc API documentation is not thick (many methods contain a single line of documentation), but it is complete. For more details, take a look at the Developer's Guide. This 115 page PDF document, which is distributed with the download ZIP file, provides more explanation about LWUIT features and often provides example code for how to use LWUIT classes. The download also comes with a sample application that demonstrates most of the new toolkit. Finally, Jonathan Knudsen has also provided a nice set of introductory tutorials on many features and aspects of LWUIT. These can be found on the project's web site.

LWUIT's Future
The LWUIT library was just released for general public consumption at JavaOne. It is still an early access library, but as such it holds great promise. Expect the source code to be released this summer. In fact, Yoav Barel indicated in his talk at JavaOne that the LWUIT project would be put in open source this summer. As an open source project, one would hope and anticipate that, as its capabilities grow, its quality will improve and it will be ported to even more environments.


Jim White is an instructor with Intertech Training. He is also co-author of Java 2 Micro Edition, (Manning).
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date