Java Reference
In-Depth Information
Constant Value
DATE Passed if the DateField should be used for entering a date only.
DATE_TIME Used for creating a DateField to enter both date and time information.
TIME
Used to enter time information only.
The DateField has two constructors in which a label and the mode can be specified. Using the
second constructor, an additional TimeZone can be passed. The following code snippet shows how a
DateField for entering the date of birth can be initialized:
DateField dateOfBirth = new DateField ("Date of birth:",
DateField.DATE);
After you enter the date into the DateField , it can be accessed using the getDate() method. The
DateField offers some additional methods for getting information about the input mode and
methods for setting the date and the input mode as well. The concrete usage of the DateField is
shown in Chapter 9 in the Blood Sugar Log application .
Further Screen Classes: List and TextBox
The current version of the TeleTransfer MIDlet shows how to use the Form and the
corresponding items available in the lcdui package. The application consists of one main form that
holds all application widgets. However, your main form is rather long now, so the question arises how
to improve the usability of the application. This section shows how to structure the user interface by
using multiple screens and introduces the List and TextBox classes.
The List Class
One possibility to clean up the user interface is to move the currency selection to a separate screen. It
takes a lot of space and may need even more room if additional options are added. Also, you can
assume that the currency is not changed very often.
You could create a new Form and just move the ChoiceGroup there. However, lcdui provides a
special List class inherited from Screen for this purpose. The advantage of the List class is that it
provides the IMPLICIT mode that was already mentioned in the section " Selecting Elements Using
ChoiceGroups . " Using the IMPLICIT mode, the application gets immediate notification when an item
is selected. Whenever an element in the List is selected, a Command of the type
List.SELECT_COMMAND is issued. As in the ChoiceGroup , the elements consist of String s
and optional Image s.
For initializing the List , the lcdui packages offers constructors. The constructors work like the
ChoiceGroup constructors. The first one creates an empty List with a given title and type only.
The second one takes the title, the type, an array of String s as initial amount of List elements, and
an optional array of Image s for each List element. In the implementation of the TeleTransfer
application, you implement a new class CurrencyList extending List that will be used as your
new currency selector. Since you will use the IMPLICIT mode, you need to implement a command
listener, so you can already add the corresponding declaration:
public class CurrencyList extends List implements CommandListener {
To set the labels of the main form TextFields according to the index of the selected element in the
CurrencyList , you create two String arrays, CURRENCY_NAMES and
CURRENCY_FRACTIONS :
static final String [] CURRENCY_NAMES = {"Dollar", "Euro", "Yen"} ;
Search WWH ::




Custom Search