Basic HTML version of Foils prepared 13 October 97

Foil 36 AWT Components -- Text Fields & Areas

From Java Tutorial, July 1, 1996 CSC499(JSU) CPS406/606 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox

TextFields and TextAreas for Foil 36
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:
  • tf.setEditable(false);
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.

in Table To:


© 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 Wed Apr 1 1998