0% found this document useful (0 votes)
6 views4 pages

Calculator Java Swing

This Java program creates a graphical user interface for a registration form using AWT. It includes fields for name, Gmail, address, gender selection, known languages, and class choice, along with a submit button. Upon submission, a confirmation message is displayed, and the window can be closed properly.

Uploaded by

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

Calculator Java Swing

This Java program creates a graphical user interface for a registration form using AWT. It includes fields for name, Gmail, address, gender selection, known languages, and class choice, along with a submit button. Upon submission, a confirmation message is displayed, and the window can be closed properly.

Uploaded by

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

import java.awt.

*;
import java.awt.event.*;

public class Sample extends Frame {


Label titleLabel, nameLabel, gmailLabel, addressLabel, genderLabel,
languageLabel, choiceLabel, submissionLabel;
TextField nameField, gmailField;
CheckboxGroup genderGroup;
Checkbox maleCheckbox, femaleCheckbox;
Checkbox languageCheckbox1, languageCheckbox2, languageCheckbox3;
Choice choice;
Button submitButton;
TextArea addressField;

public Sample() {
setBackground(Color.LIGHT_GRAY);
setLayout(null);

titleLabel = new Label("Registration Form", Label.CENTER);


titleLabel.setFont(new Font("Arial", Font.BOLD, 16));
titleLabel.setBounds(100, 30, 200, 30);
add(titleLabel);

nameLabel = new Label("Name:", Label.CENTER);


nameLabel.setBounds(50, 70, 50, 20);
add(nameLabel);
nameField = new TextField(20);
nameField.setBounds(150, 70, 200, 20);
add(nameField);

gmailLabel = new Label("Gmail:", Label.CENTER);


gmailLabel.setBounds(50, 110, 50, 20);
add(gmailLabel);
gmailField = new TextField(20);
gmailField.setBounds(150, 110, 200, 20);
add(gmailField);

addressLabel = new Label("Address:", Label.CENTER);


addressLabel.setBounds(50, 150, 50, 20);
add(addressLabel);
addressField = new TextArea(5, 20);
addressField.setBounds(150, 150, 200, 100);
add(addressField);

genderLabel = new Label("Gender:", Label.CENTER);


genderLabel.setBounds(50, 270, 50, 20);
add(genderLabel);
genderGroup = new CheckboxGroup();
maleCheckbox = new Checkbox("Male", genderGroup, true);
maleCheckbox.setBounds(150, 270, 50, 20);
add(maleCheckbox);
femaleCheckbox = new Checkbox("Female", genderGroup, false);
femaleCheckbox.setBounds(220, 270, 60, 20);
add(femaleCheckbox);

languageLabel = new Label("Known Language:", Label.CENTER);


languageLabel.setBounds(45, 310, 100, 20);
add(languageLabel);
languageCheckbox1 = new Checkbox("Java");
languageCheckbox1.setBounds(150, 310, 50, 20);
add(languageCheckbox1);
languageCheckbox2 = new Checkbox("Python");
languageCheckbox2.setBounds(220, 310, 60, 20);
add(languageCheckbox2);
languageCheckbox3 = new Checkbox("C++");
languageCheckbox3.setBounds(290, 310, 50, 20);
add(languageCheckbox3);

choiceLabel = new Label("Class:", Label.CENTER);


choiceLabel.setBounds(50, 350, 100, 20);
add(choiceLabel);
choice = new Choice();
choice.add("1CA");
choice.add("2CA");
choice.add("3CA");
choice.setBounds(150, 350, 100, 20);
add(choice);

submitButton = new Button("Submit");


submitButton.setBounds(150, 400, 100, 20);
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submissionLabel = new Label("Your form has been submitted
successfully!", Label.CENTER);
submissionLabel.setFont(new Font("Arial", Font.BOLD, 12));
submissionLabel.setBounds(50, 430, 300, 20);
add(submissionLabel);
validate();
}
});
add(submitButton);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

setSize(400, 500);
setVisible(true);
}

public static void main(String[] args) {


new Sample();
}
}
Output:

You might also like