Text field and Text area:
The class TextComponent gives the functionality for editing and selecting the text. Its two subclasses TextField and TextArea inherit the functionality to implement a single line of text or multiple lines of text correspondingly. A text in the component could be read-only or editable.
The TextField class implements a single line of optionally editable text. A size of the text field is measured in columns. A few initial text and a preferred size could be specified whenever a text field is created.
TextField( )
TextField(String text)
TextField(int columns)
TextField(String text, int columns)
// Illustrating TextField
import java.awt.*;
import java.applet.*;
public class TextFieldApplet extends Applet
{
public void init ( );
{
TextField entryField = new TextField(18);
entryField.setFont(new Font("Serif",Font.PLAIN, 12);
entryField.setText("Go ahead and type");
add(entryField);
}
}
The TextArea class implements multiple lines of optionally editable text. These lines are divided through '\n'(newline) character. The size of the text area is measured in rows and columns. Whenever creating text areas, the intial text and the pereferred size of the component could be specified.