Basic HTML version of Foils prepared Sept 21 1998

Foil 36 AWT Components -- Text Fields & Areas

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

TextFields and TextAreas for Foil 36
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);
The text which is displayed can be changed:
  • tf.setText("now show a new text");
If the user types input into the text field, it can be obtained:
  • stringvar = tf.getText();
Or you can disallow the user to type:
  • tf.setEditable(false);
The TextArea class also has these methods, but it can display multiple lines.
When the user types in text and presses "return" or "enter", an ActionEvent is generated, so, similarly to Buttons, an ActionListener must be provided.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998