Java Reference
In-Depth Information
The
TextBox
Class
Beneath
Alert
,
List
, and
Form
, there is only one further subclass of
Screen
: the
TextBox
. The
TextBox
allows the user to enter multi-line text on a separate screen. The constructor parameters and
the constraint constants are identical to those of
TextField
.
As for the currency list, you can also add a new screen enabling the user to enter a transfer reason if
desired. Similar to the
CurrencyList
, you implement a new class handling the commands related to
the new screen. However, this time it is derived from the
TextBox
. Again, you implement the
CommandListener
interface:
public class TransferReason extends TextBox implements
CommandListener {
In the
TextBox
, you provide two commands,
okCommand
for applying the entered text and
clearCommand
for clearing the text:
static final Command okCommand = new Command ("OK", Command.BACK, 1);
static final Command clearCommand = new Command ("Clear",
Command.SCREEN, 2);
Again, you store a reference back to the
TeleTransfer
MIDlet in the
TransferReason
TextBox
:
TeleTransfer teleTransfer;
The constructor gets the reference back to
TeleTransfer
MIDlet and stores it in the variable
declared previously. You also add the commands to the
TextBox
, and register it as
CommandListener
:
public TransferReason (TeleTransfer teleTransfer) {
super ("Transfer Reason", "", 50, TextField.ANY);
this.teleTransfer = teleTransfer;
addCommand (okCommand);
addCommand (clearCommand);
setCommandListener(this);
}
Your
commandAction()
implementation clears the text or returns to the main screen, depending on
the
Command
selected:
public void commandAction (Command c, Displayable d) {
if (c == clearCommand) {
setString ("");
}
else if (c == okCommand) {
Search WWH ::
Custom Search