Java Reference
In-Depth Information
mainForm.append (amountWhole);
mainForm.append (amountFraction);
}
When the application is started, you request the display to show your money transfer form by calling
the application start by calling the
startApp()
method. So you implement this method accordingly:
public void startApp() {
display.setCurrent (mainForm);
}
Please note that
startApp()
is called also when the MIDlet resumes from the paused state, so you
cannot move the initialization code from the constructor to this method.
Both
pauseApp()
and
destroyApp()
are declared as abstract in the
MIDlet
class, so you need
to implement these methods in your application, even if you do not have real content for them. You just
provide empty implementations, like in the
HelloMidp
example in the first section:
public void pauseApp() {
}
public void destroyApp (boolean unconditional) {
}
Selecting Elements Using
ChoiceGroup
s
In the previous section, you created a simple to enter information for transferring money between two
accounts. Now you will extend the application to allow the user to select different currencies. For this
purpose, you will now add a
ChoiceGroup
to your application.
The
ChoiceGroup
is an MIDP UI widget enabling the user to choose between different elements in a
Form
. These elements consist of simple
String
s, but can display an optional image per element as
well.
ChoiceGroup
s can be of two different types. Corresponding type constants are defined in the
Choice
interface. These constants are used in the
List
class as well; the
List
class allows an
Table 3.4.
Choice
Type Constants
Constant
Value
EXCLUSIVE
Specifies a
ChoiceGroup
or
List
having only one element selected at the
s
ame time.
IMPLICIT
Valid for
List
s only. It lets the
List
send
Command
s to indicate state changes.
MULTIPLE
In contrast to
EXPLICIT
,
MULTIPLE
allows the selection of multiple elements.
The
ChoiceGroup
constructor requires at least a label and a type value. Additionally, a
String
array and an
Image
array containing the elements can be passed to the constructor. Elements can also
be added dynamically using the
append()
method. The
append()
method has two parameters, a
String
for the label and an
Image
. In both cases, the image parameter may be
null
if no images
are desired.
In order to add a
ChoiceGroup
to the
TeleTransfer
application, you introduce a new variable
currency
of type
ChoiceGroup
. By setting the type to
EXCLUSIVE
, you get a
ChoiceGroup
where only one item can be selected at a time. You directly add elements for the United States (USD),
the European Union (EUR), and Japan (JPY) by passing a
String
array created inline. The
ChoiceGroup
enables the user to choose between three currencies that are represented textually by
Search WWH ::
Custom Search