Java Reference
In-Depth Information
public TextBox(String title, String text, int maxSize, int constraints)
The title is used as the screen title, while
text
and
maxSize
determine the initial text and
maximum size of the text box. Finally,
constraints
can be used to restrict the user's input.
Constants from the
TextField
class are used to specify the type of input required:
•
ANY
allows any type of input that is supported by the device.
•
NUMERIC
restricts the input to integers.
•
DECIMAL
allows numbers with fractional parts.
•
PHONENUMBER
requires a telephone number.
•
EMAILADDR
input must be an e-mail address.
•
URL
input must be a web address.
It's up to the implementation to determine how these constraints are enforced. The toolkit
emulators simply don't allow invalid input; for example, a
NUMERIC TextBox
doesn't allow you to
enter alphabetic characters.
The preceding constraints may be combined with the flags listed next. Constraints limit
the behavior of users, while flags define the behavior of the
TextBox
.
•
PASSWORD
characters are not shown when entered; generally, they are represented by
asterisks.
•
UNEDITABLE
indicates text that cannot be edited.
•
SENSITIVE
is used to flag text that the implementation should not store. Some input
schemes store input from the user for later use in autocompletion. This flag indicates
that the text is off limits and should not be saved or cached.
•
NON_PREDICTIVE
indicates that you are expecting the user to enter text that any text-
predicting input scheme will probably not be able to guess. For example, if you're
expecting the user to enter an order number like Z51002S, you would use this flag to
tell the input scheme to not bother trying to predict the input.
•
INITIAL_CAPS_WORD
is used for input where each word should be capitalized.
•
INITIAL_CAPS_SENTENCE
indicates input where the first character of each sentence
should be capitalized.
If you don't want the
TextBox
to perform any validation, use
ANY
or its numerical equiva-
lent,
0
, for the
constraints
parameter in the constructor.
The flags may be combined with any of the other constraints using the
OR
operator. For
example, to create a
TextBox
that constrains input to an e-mail address but keeps the entered
data hidden, you would do something like this:
Displayable d = new TextBox("Email", "", 64,
TextField.EMAILADDR | TextField.PASSWORD);
If you think about it, though,
PASSWORD
is probably more trouble than it's worth. The point
of
PASSWORD
fields, at least on desktop machines, is to keep someone walking past your computer
Search WWH ::
Custom Search