1 -////////////////////////////// Create a Button
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.
}
}
2 -///////////////// Create Checkbox
import [Link].*;
import [Link].*;
public class MyFrame extends Frame
{
Checkbox c1, c2;
MyFrame()
{
setSize(400, 200);
setTitle("My Application");
setLayout(new FlowLayout());
setVisible(true);
c1 = new Checkbox("Male");
c2 = new Checkbox("Female");
add(c1);
add(c2);
}
public static void main(String[] args)
{
MyFrame mf = new MyFrame();
}
}
3-/////////////////////////// Radio Button
import [Link].*;
import [Link].*;
public class MyFrame extends Frame
{
Checkbox c1, c2;
CheckboxGroup cbg;
MyFrame()
{
setSize(400, 200);
setTitl e("My Application");
setLayout(new FlowLayout());
setVisible(true);
cbg = new CheckboxGroup();
c1 = new Checkbox("Male", cbg, false);
c2 = new Checkbox("Female", cbg, false);
add(c1);
add(c2);
}
public static void main(String[] args)
{
MyFrame mf = new MyFrame();
}
}
4 -/////////////////////
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();
}
}