Awt program1
import [Link].*;
public class AwtProgram1 {
public AwtProgram1()
{
Frame f = new Frame();
Button btn=new Button("Hello World");
[Link](80, 80, 100, 50);
[Link](btn); //adding a new Button.
[Link](300, 250); //setting size.
[Link]("JavaTPoint"); //setting title.
[Link](null); //set default layout for frame.
[Link](true); //set frame visibility true.
}
public static void main(String[] args) {
// TODO Auto-generated method stub
AwtProgram1 awt = new AwtProgram1(); //creating a frame.
}
}
Output:
Program 2
Java awt Example (extending Frame Class)
Consider the following program in which we have created a user's form GUI, which has three
fields, i.e., first name, last name, and date of birth.
import [Link].*;
public class AwtApp extends Frame {
AwtApp(){
Label firstName = new Label("First Name");
[Link](20, 50, 80, 20);
Label lastName = new Label("Last Name");
[Link](20, 80, 80, 20);
Label dob = new Label("Date of Birth");
[Link](20, 110, 80, 20);
TextField firstNameTF = new TextField();
[Link](120, 50, 100, 20);
TextField lastNameTF = new TextField();
[Link](120, 80, 100, 20);
TextField dobTF = new TextField();
[Link](120, 110, 100, 20);
Button sbmt = new Button("Submit");
[Link](20, 160, 100, 30);
Button reset = new Button("Reset");
[Link](120,160,100,30);
add(firstName);
add(lastName);
add(dob);
add(firstNameTF);
add(lastNameTF);
add(dobTF);
add(sbmt);
add(reset);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
AwtApp awt = new AwtApp();
}
}