To simplify user interaction and make data entry easier, you can use java controls. Controls are components, such as buttons, labels and text boxes, that can be added to containers like frames, panels and applets. The Java.awt package provides an integrated set of classes to manage user interface components.
To accept textual data from a user, AWT provided two classes, TextField and TextArea. The TextField handles a single line of text and does not have scrollbars, whereas the TextArea class handles multiple lines of text. Both the classes are derived from the TextComponent class. Hence share many common methods. TextFields are different from labels in that they can be edited; labels are good for just displaying text, while for getting text input from the user, the best option is TextField.
TextFields provide an area where you can enter and edit a single line of text. To create a text field, use one of the following constructors:
TextField() creates an empty TextField with no specified width.
TextField(int) creates an empty text field with enough width to display the specified number of characters (this has been depreciated in Java2).
TextField(String) creates a text field initialized with the given string.
TextField(String, int) creates a text field with specified text and specified width.
For example, the following line creates a text field 25 characters wide with the string "Brewing Java" as its initial contents:
TextField txtfld = new TextField ("Brewing Java", 25);add(txtfld);