Untitled
unknown
plain_text
10 months ago
3.4 kB
14
Indexable
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RegistrationFormAWTSwing extends Frame implements ActionListener {
// AWT Components
Label nameLabel, mobileLabel, genderLabel, addressLabel, stateLabel;
TextField nameField, mobileField;
TextArea addressArea;
Choice stateChoice;
Button submitBtn;
Checkbox male, female;
CheckboxGroup genderGroup;
// Swing Component
JLabel titleLabel;
RegistrationFormAWTSwing() {
// Frame settings
setTitle("Registration Form");
setSize(400, 400);
setLayout(null);
setVisible(true);
// Swing Title Label
titleLabel = new JLabel("Registration Form", JLabel.CENTER);
titleLabel.setBounds(100, 40, 200, 30);
add(titleLabel);
// Name
nameLabel = new Label("Name:");
nameLabel.setBounds(50, 90, 60, 20);
add(nameLabel);
nameField = new TextField();
nameField.setBounds(150, 90, 150, 20);
add(nameField);
// Mobile
mobileLabel = new Label("Mobile No:");
mobileLabel.setBounds(50, 130, 80, 20);
add(mobileLabel);
mobileField = new TextField();
mobileField.setBounds(150, 130, 150, 20);
add(mobileField);
// Gender
genderLabel = new Label("Gender:");
genderLabel.setBounds(50, 170, 60, 20);
add(genderLabel);
genderGroup = new CheckboxGroup();
male = new Checkbox("Male", genderGroup, false);
male.setBounds(150, 170, 60, 20);
add(male);
female = new Checkbox("Female", genderGroup, false);
female.setBounds(220, 170, 70, 20);
add(female);
// Address
addressLabel = new Label("Address:");
addressLabel.setBounds(50, 210, 60, 20);
add(addressLabel);
addressArea = new TextArea();
addressArea.setBounds(150, 210, 150, 50);
add(addressArea);
// State (Dropdown)
stateLabel = new Label("State:");
stateLabel.setBounds(50, 280, 60, 20);
add(stateLabel);
stateChoice = new Choice();
stateChoice.add("Maharashtra");
stateChoice.add("Karnataka");
stateChoice.add("Gujarat");
stateChoice.add("Delhi");
stateChoice.add("Other");
stateChoice.setBounds(150, 280, 150, 20);
add(stateChoice);
// Submit Button
submitBtn = new Button("Submit");
submitBtn.setBounds(150, 320, 80, 30);
submitBtn.addActionListener(this);
add(submitBtn);
}
// Action Listener
public void actionPerformed(ActionEvent e) {
if (e.getSource() == submitBtn) {
String data = "Name: " + nameField.getText() +
"\nMobile: " + mobileField.getText() +
"\nGender: " + genderGroup.getSelectedCheckbox().getLabel() +
"\nAddress: " + addressArea.getText() +
"\nState: " + stateChoice.getSelectedItem();
JOptionPane.showMessageDialog(null, data, "Submitted Data", JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] args) {
new RegistrationFormAWTSwing();
}
}
Editor is loading...
Leave a Comment