Unit-3 User Interface Components Using Swing
Unit-3 User Interface Components Using Swing
Text Field:-The object of a TextField class is a text component that allows the editing of a single line text. It inherits
TextComponent class.
Java AWT TextField Example
import java.awt.*;
class TextFieldExample{
public static void main(String args[]){
Frame f= new Frame("TextField Example");
TextField t1,t2;
t1=new TextField("Welcome to Javatpoint.");
t1.setBounds(50,100, 200,30);
t2=new TextField("AWT Tutorial");
t2.setBounds(50,150, 200,30);
f.add(t1); f.add(t2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Text Area:-The object of a TextArea class is a multi line region that displays text. It allows the editing of multiple line text. It
inherits TextComponent class.
import java.awt.*;
public class TextAreaExample
{
TextAreaExample(){
Frame f= new Frame();
TextArea area=new TextArea("Welcome to javatpoint");
area.setBounds(10,30, 300,300);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new TextAreaExample();
}
}
Java JPasswordField:-The object of a JPasswordField class is a text component specialized for password entry. It allows
the editing of a single line of text. It inherits JTextField class.