站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Programming Wireless Devices with the Java2 Platform

Programming Wireless Devices with the Java2 Platform

[ directory ] Previous Section Next Section

9.4 Form

A Form is a Screen that may contain a combination of Items, including StringItems, ImageItems, editable TextFields, editable DateFields, Gauges, and ChoiceGroups. Any of the subclasses of Item defined by the MIDP Specification may be contained within a Form. The device handles layout, traversal, and possible scrolling automatically. The entire contents of the Form scroll up and down together. Horizontal scrolling is not generally available. This means that the MIDP Specification does not forbid a device to implement this, but it is not endorsed. When a device allows only vertical scrolling, the layout and traversal model is easier and matches the limited set of controls available on a typical mobile information device. Applications must be written with this limitation in mind. For example, a CustomItem subclass needs to designed so that it works in varying screen widths without any horizontal scrolling support.

graphics/new_icon.gif

The methods for modifying the sequence of Items stored in a Form include insert, append, delete, get, set, and size. MIDP 2.0 devices also have a deleteAll method. Items within a Form are referenced by indices. The first Item in a Form has an index of zero and the last has the index size()-1.

The code sample below creates an empty Form container to be used as an options selection screen. This simple example has a title for the Form and Commands for accepting and canceling the Form contents. This kind of empty Form should be avoided in real applications.

Note that we will return back to this example in Chapter 10 when we illustrate the use of the Form class in more detail. The code below serves as a starting point for an "Options" selection form of a photo album application. The example will continue in Section 10.1, "Item," where we show how to add different Item class instances to this Form.

graphics/09inf08.gif
Form form = new Form("Options");
form.addCommand(backCommand);
form.addCommand(okCommand);
form.setCommandListener(this);
// Items are added later (see below)
display.setCurrent(form);

Refer to Chapter 10, "MIDP High-Level User Interface ?Form" for more information on using the Form class.

    [ directory ] Previous Section Next Section