A TextField is a box in which the user enters a single line of text: TextField tf = new TextField ( 30 ) ; |
The argument is an integer giving the width of the TextField in characters. |
TextFields have methods either to get the text that a user typed in, or to write some text in the box: String word1 = tf.getText ( ) ; tf.setText ( "Thanks!" ) ; |
Note that when the user presses enter, a TextField can also generate an ActionEvent, but it is generally better user design to respond to button events. |