Book Image

LWUIT 1.1 for Java ME Developers

By : Biswajit Sarkar
Book Image

LWUIT 1.1 for Java ME Developers

By: Biswajit Sarkar

Overview of this book

<p>Writing appealing cross-device applications today in Java ME is challenging as implementation differences in fonts, layout, and menus can make your application look and behave very differently on different devices. So far, the only way out has been low-level programming with its associated complexity.<br /><br />The Lightweight UI Toolkit (LWUIT), an open source Java library, offers Java ME developers an easy-to-use API for creating impressive user interfaces with a device-independent look and feel. The LWUIT library contains many components and tools for bringing consistency and visual gloss to the user interface of your applications, and this book will take you through all of this, to help you get the user interfaces you want.<br /><br />Java ME allows us to write applications that are, generally speaking, portable across a wide range of small devices that support the platform. While the basic functionalities usually work well on all supported devices, the area that does pose problems for developers is the User Interface. Native implementations of javax.microedition.lcdui &ndash; the primary API for UIs in Java ME &ndash; differ so widely from one device to another that maintaining a device-independent and uniform look and feel is virtually impossible. Another problem with the javax.microedition.lcdui package is that it does not support components and capabilities that can fully satisfy present day user expectations. The Lightweight UI Toolkit is the solution to these problems. LWUIT offers a wide range of components with a device-independent look and feel for building UIs. While some of these widgets are also available under lcdui, there are a number of new ones too. These additions enable application developers to design UIs that can come very close to their desktop counterparts in terms of visual sophistication and LWUIT is not just about new components either. The API supports a whole range of new functionalities (like Theming and Transitions) too.<br /><br />This book takes Java ME developers through the library, with examples showing how to use the main components and functionalities. It also goes beyond a description of what is available by showing how to extend the library by plugging in custom-built classes.</p>
Table of Contents (18 chapters)
LWUIT 1.1 for Java ME Developers
Credits
About the Author
About the Reviewers
Preface

Preface

The Lightweight Toolkit (LWUIT) is designed to help developers to create highly attractive User Interfaces for MIDP 2.0 and CLDC 1.1 compliant small devices like mobile phones. This toolkit supports a number of interesting widgets and features like theming, animations, transitions, and logging. LWUIT also addresses the issue of fragmentation by making it possible to implement screens with a device independent look and feel.

This book covers the widgets and functionalities of the library in detail, demonstrating their use with a large number of examples and a profusion of screenshots. A number of structural and architectural issues are discussed to help you gain insight into the inner workings of the library.

LWUIT is an evolving library and we are bound to see modifications and additions to its current repertoire. The knowledge you gain from this book will help you significantly in understanding these changes and in remaining up-to-date. The Lightweight Toolkit Library is an external API that is not an integral part of the Java platform and has to be bundled with an application meant for a physical device. One implication of this is that any application you write based on a given version (like version 1.1) will not become obsolete and will work on future devices too.

This book will equip you with the knowledge and skills required to create applications that will impress users with visual sophistication.

What this book covers

Chapter 1 tells you what LWUIT is all about and, broadly, how it operates. Starting with an overview of LWUIT which present the widgets and the functional features, this chapter goes on to discuss the basic architecture of LWUIT and ends with introductions to the two classes that are its foundations—LWUITImplementation and Display.

Chapter 2 lists the items that you will need to download and tells you where to find them. It prepares you for trying out the examples in the book and for creating your own applications by building a demo project. Next, you get to know the Component class, the component rendering process, and the Graphics class. Finally, this chapter lays the foundation for using Style and Animation with components.

Chapter 3 deals with the Container class, which is designed to be the holder of components. There are a number of descendants of Container—the Form, the Dialog, the Calendar and the TabbedPane. These classes also are discussed in detail with examples to show how they can be used in applications.

Chapter 4 covers Labels and the three components that are its descendants. These are the Button, the CheckBox and the RadioButton. RadioButtons exhibit special properties when they work with the ButtonGroup class and this aspect is demonstrated through an example. This chapter also takes a look at the Border class, which is used in the examples.

Chapter 5 demonstrates how flexible a List, and its subclass ComboBox, can be. This flexibility is shown through the examples that use custom renderers to enhance the appearance and functionality of lists and combo boxes.

Chapter 6 explores TextArea and TextField—the two classes that enable users to enter, display and edit text. A text field has the interesting property of in-place editing and this is treated in detail in this chapter.

Chapter 7 takes you through the various layout managers that arrange components on containers. There are six layout managers and the examples show the different ways in which these classes place components. The root of these six classes is the Layout class, which too is studied here.

Chapter 8 shows how custom components can be built. Building such a component involves not only visual aspects but also issues like styling, event handling and event generation. All of these topics are dealt with in this chapter through the examples.

Chapter 9 demonstrates how LWUIT handles various non-code elements that may be required by an application. Images, Fonts, and Animation Resources are examples of such elements. Resource files are used to package these elements and the Resources class provides the methods for extracting them from a resource file. The LWUIT bundle contains LWUIT Designer, which is a very convenient utility for creating resource files. This chapter examines how resource files are built and used.

Chapter 10 is about Themes. Themes are used to establish visual coherence through all the screens of an application. The LWUIT Designer is the tool that displays, edits and builds the themes that define how your applications will look. In this chapter, you will learn about themes, their usage and how they can be created.

Chapter 11 shows off two fascinating functionalities of LWUIT—Animations and Transitions. Animations involve repeated rendering on a component while Transitions determine the way in which a form is moved out of or brought into display. In this chapter, you will study these two features and see how to use them in actual applications. You will also see how to develop a custom transition which demonstrates the process of such customization.

Chapter 12 shows you how the Painter interface can be used to customize the appearance of a component’s background. This chapter also explains how a transparent or translucent layer (like a glass pane) can be placed over a form to implement interesting visual effects.

Chapter 13 covers two useful utilities that come with the LWUIT library. These are the Effects and the Log classes. The Effects class simulates the reflection of an image and appends the reflection to the original image. The Log class enables you to monitor at runtime the inner workings of the classes that you write. This can be a very effective debugging tool. This chapter demonstrates the use of Effects and Log classes. It also examines the structure of Log class through an example that builds its subclass to provide additional capabilities.

What you need for this book

The following are required for this book:

The LWUIT bundle—this can be downloaded from https://lwuit.dev.java.net/servlets/ProjectDocumentList

A JDK. If you do not have one installed on your computer, you can get the latest version at http://java.sun.com/javase/downloads/index.jsp

The Sprint Wireless Toolkit 3.3.2 which is available at http://developer.sprint.com/site/global/develop/technologies/java_me/p_java_me.jsp

Who this book is for

This book is for Java ME developers who want to create compelling user interfaces for Java ME applications, and want to use LWUIT to make this happen.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code will be set as follows:

public class DemoForm extends MIDlet
{
public void startApp()
{
//initialize the LWUIT Display
//and register this MIDlet
Display.init(this);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be shown in bold:

public void destroyApp(boolean unconditional)
{
}
//act on the command
public void actionPerformed(ActionEvent ae)

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/7405_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.