Java Reference
In-Depth Information
The interface to the
TextField
class provides several low-level operations that let you
interact directly with the contents of a
TextField
, including the following methods:
•
getCaretPosition
: Returns the current input position
•
getChars
: Copies the contents of the
TextField
into the array you provide, starting
at position zero
•
getString
: Returns the contents of the
TextField
as a string
•
delete
: Lets you delete a specific number of characters starting at the offset you
provide
•
insert
: Inserts the character array or string you provide at the specified location
•
setChars
: Lets you replace partial runs of characters in the
TextField
by specifying
new characters, an offset, and a length
•
setString
: Lets you replace the entire contents of the
TextField
with a new string
For most applications, you'll simply set the desired constraints and input mode
(quite possibly using the NetBeans Properties pane) when you create the item, and then
get the text of the item when you transition to a new
Form
.
Introducing the DateField
The
DateField
class is an editable component for presenting calendar (date and time)
information. Using the
DateField
, you can obtain constrained user input for the date,
time, or both the date and time by specifying the
DATE
,
TIME
, or
DATE_TIME
input modes.
Figure 5-6 shows an example of the
DateField
class in action.
The
DateField
extends
Item
with four methods:
•
getDate
: Returns the date you enter
•
setDate
: Sets the item to the indicated date
•
getInputMode
: Returns the input mode you set for the item
•
setInputMode
: Sets the input mode