Java Reference
In-Depth Information
private Image loadImage(String name) {
Image image = null;
try {
image = Image.createImage(name);
}
catch (IOException ioe) {
System.out.println(ioe);
}
return image;
}
}
To see images in this example, you'll need to either download the examples from the
topic's web site or supply your own images. With the J2ME Wireless Toolkit, image files should
go in the res directory of your toolkit project directory. TravelList expects to find three images
named airplane.png , car.png , and hotel.png .
Construction of the List itself is very straightforward. This application also includes a Next
command and an Exit command, which are both added to the List . The TravelList instance
is registered as the CommandListener for the List . If the Next command or the List 's IMPLICIT
command is fired off, you simply retrieve the selected item from the List and show it in an Alert .
The Next command, in fact, is not strictly necessary in this example since you can achieve
the same result by clicking the select button on one of the elements in the List . Nevertheless,
it might be a good idea to leave it there. Maybe all of the other screens in your application have
a Next command, so you could keep it for user interface consistency. It never hurts to provide
the user with more than one consistent way of doing things.
The difference between EXCLUSIVE and IMPLICIT lists can be subtle. Try changing the List
in this example to EXCLUSIVE to see how the user experience is different.
Creating Advanced Interfaces with Forms
A Form is a screen that can include an arbitrary collection of user-interface controls, called items . In
a movie ticket reservation MIDlet, you might use a form to allow the user to enter a date and a
Zip code on one screen.
Keep in mind that the minimum screen size for a MID is 96×54 pixels. You can't fit a whole
lot on a screen this size, nor should you try to. Forms that don't fit on the screen will automat-
ically be made scrollable if needed, so your MIDlet will be able to show forms, regardless of the
screen size. Scrolling forms tend to be confusing to users, however, so you should keep your
forms as small as possible.
The javax.microedition.ldcui.Form class itself is fairly simple. One way to create a Form is
by specifying a title:
public Form(String title)
In essence, a Form is a collection of items. Each item is represented by an instance of the
Item class. If you have all the items ahead of time, you can pass them to Form 's other constructor:
public Form(String title, Item[] items)
Search WWH ::




Custom Search