1 |
To add a text field for display or input one line of text (in this case, 30 characters wide):
-
TextField tf = new TextField("initial text", 30);
-
add(tf);
|
2 |
The text which is displayed can be changed:
-
tf.setText("now show a new text");
|
3 |
If the user types input into the text field, it can be obtained:
-
stringvar = tf.getText();
|
4 |
Or you can disallow the user to type:
|
5 |
The TextArea class also has these methods, but it can display multiple lines.
|
6 |
When the user types in text and presses "return" or "enter", an ActionEvent is generated, so, similarly to Buttons, an ActionListener must be provided.
|