Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.awt.Component | +----java.awt.TextComponent | +----java.awt.TextField
TextField
object is a text component
that allows for the editing of a single line of text.
For example, the following image depicts a frame with four
text fields of varying widths. Two of these text fields
display the predefined text "Hello"
.
Here is the code that produces these four text fields:
TextField tf1, tf2, tf3, tf4; // a blank text field tf1 = new TextField(); // blank field of 20 columns tf2 = new TextField("", 20); // predefined text displayed tf3 = new TextField("Hello!"); // predefined text in 30 columns tf4 = new TextField("Hello", 30);
Every time the user types a key in the text field, AWT sends two action events to the text field. The first one represents the key press and the second one, the key release. Each action event embodies the state of the system at the time that some action occurred. The properties of an action event indicate which key was pressed, what modifier keys were also pressed, and the time at which the event occurred.
Since the event is an instance of ActionEvent
,
the TextField
class's processEvent
method examines the event and passes it along to
processActionEvent
. The latter method redirects the
event to any ActionListener
objects that have
registered an interest in action events generated by this
text field.
Fields inherited from class java.awt.TextComponent |
textListener |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Constructor Summary | |
TextField()
|
|
TextField(String text)
|
|
TextField(int columns)
|
|
TextField(String text,
int columns)
|
Method Summary | |
void | addActionListener(ActionListener l)
|
void | addNotify()
|
boolean | echoCharIsSet()
|
int | getColumns()
|
char | getEchoChar()
|
Dimension | getMinimumSize(int columns)
|
Dimension | getMinimumSize()
|
Dimension | getPreferredSize(int columns)
|
Dimension | getPreferredSize()
|
Dimension | minimumSize(int columns)
|
Dimension | minimumSize()
|
String | paramString()
|
Dimension | preferredSize(int columns)
|
Dimension | preferredSize()
|
void | processActionEvent(ActionEvent e)
ActionListener objects.
|
void | processEvent(AWTEvent e)
|
void | removeActionListener(ActionListener l)
|
void | setColumns(int columns)
|
void | setEchoChar(char c)
|
void | setEchoCharacter(char c)
|
Methods inherited from class java.awt.TextComponent |
addTextListener, getCaretPosition, getSelectedText, getSelectionEnd, getSelectionStart, getText, isEditable, paramString, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TextField()
public TextField(String text)
text
- the text to be displayed.
public TextField(int columns)
columns
- the number of columns
public TextField(String text, int columns)
text
- the text to be displayed.
columns
- the number of characters.
Method Detail |
public void addNotify()
public char getEchoChar()
An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password.
public void setEchoChar(char c)
An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password.
c
- the echo character for this text field.
public void setEchoCharacter(char c)
setEchoChar(char)
.
public boolean echoCharIsSet()
An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password.
true
if this text field has
a character set for echoing;
false
otherwise.public int getColumns()
public void setColumns(int columns)
columns
- the number of columns.
columns
is less than zero.public Dimension getPreferredSize(int columns)
columns
- the number of columns
in this text field.
public Dimension preferredSize(int columns)
getPreferredSize(int)
.
public Dimension getPreferredSize()
public Dimension preferredSize()
getPreferredSize()
.
public Dimension getMinimumSize(int columns)
columns
- the number of columns in
this text field.
public Dimension minimumSize(int columns)
getMinimumSize(int)
.
public Dimension getMinimumSize()
public Dimension minimumSize()
getMinimumSize()
.
public void addActionListener(ActionListener l)
l
- the action listener.
public void removeActionListener(ActionListener l)
l
- the action listener.
protected void processEvent(AWTEvent e)
ActionEvent
,
it invokes the processActionEvent
method. Otherwise, it invokes processEvent
on the superclass.
e
- the event.
protected void processActionEvent(ActionEvent e)
ActionListener
objects.
This method is not called unless action events are enabled for this component. Action events are enabled when one of the following occurs:
ActionListener
object is registered
via addActionListener
.
enableEvents
.
e
- the action event.
protected String paramString()
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |