[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Awt Program

The document contains two Java AWT programs. The first program creates a simple frame with a 'Hello World' button, while the second program extends the Frame class to create a user form GUI with fields for first name, last name, and date of birth, along with submit and reset buttons. Both programs set the frame size, layout, and visibility.

Uploaded by

kavya.jagtap04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Awt Program

The document contains two Java AWT programs. The first program creates a simple frame with a 'Hello World' button, while the second program extends the Frame class to create a user form GUI with fields for first name, last name, and date of birth, along with submit and reset buttons. Both programs set the frame size, layout, and visibility.

Uploaded by

kavya.jagtap04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Awt program1

​ import java.awt.*;


​ public class AwtProgram1 {
​ public AwtProgram1()
​ {
​ Frame f = new Frame();
​ Button btn=new Button("Hello World");
​ btn.setBounds(80, 80, 100, 50);
​ f.add(btn); //adding a new Button.
​ f.setSize(300, 250); //setting size.
​ f.setTitle("JavaTPoint"); //setting title.
​ f.setLayout(null); //set default layout for frame.
​ f.setVisible(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 java.awt.*;
​ public class AwtApp extends Frame {

​ AwtApp(){
​ Label firstName = new Label("First Name");
​ firstName.setBounds(20, 50, 80, 20);

​ Label lastName = new Label("Last Name");
​ lastName.setBounds(20, 80, 80, 20);

​ Label dob = new Label("Date of Birth");
​ dob.setBounds(20, 110, 80, 20);

​ TextField firstNameTF = new TextField();
​ firstNameTF.setBounds(120, 50, 100, 20);

​ TextField lastNameTF = new TextField();
​ lastNameTF.setBounds(120, 80, 100, 20);

​ TextField dobTF = new TextField();
​ dobTF.setBounds(120, 110, 100, 20);

​ Button sbmt = new Button("Submit");
​ sbmt.setBounds(20, 160, 100, 30);

​ Button reset = new Button("Reset");
​ reset.setBounds(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();
​ }
​ }

You might also like