Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class MyFrame extends JFrame {
- private Container c;
- private JLabel title;
- private String[] dates;
- private String[] months;
- private String[] years;
- private JLabel nameLabel;
- private JTextField nameField;
- private JLabel rollNumberLabel;
- private JTextField rollNumberField;
- private JLabel dobLabel;
- private JComboBox<String> dayComboBox;
- private JComboBox<String> monthComboBox;
- private JComboBox<String> yearComboBox;
- private JLabel classLabel;
- private JTextField classField;
- private JButton registerButton;
- private JTextArea textArea;
- public MyFrame() {
- setTitle("Registration Form:");
- setBounds(300, 90, 900, 700);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setResizable(false);
- c = getContentPane();
- c.setLayout(null);
- // Title
- title = new JLabel("Registration Form:");
- title.setSize(300, 30);
- title.setLocation(300, 30);
- c.add(title);
- // Name Field
- nameLabel = new JLabel("Name:");
- nameLabel.setBounds(50, 70, 100, 30);
- c.add(nameLabel);
- nameField = new JTextField();
- nameField.setBounds(160, 70, 200, 30);
- c.add(nameField);
- // Roll Number Field
- rollNumberLabel = new JLabel("Roll Number:");
- rollNumberLabel.setBounds(50, 110, 100, 30);
- c.add(rollNumberLabel);
- rollNumberField = new JTextField();
- rollNumberField.setBounds(160, 110, 200, 30);
- c.add(rollNumberField);
- // Date of Birth Field
- dobLabel = new JLabel("Date of Birth:");
- dobLabel.setBounds(50, 150, 100, 30);
- c.add(dobLabel);
- dates = new String[32];
- months =
- new String[] {
- "",
- "Jan",
- "Feb",
- "Mar",
- "Apr",
- "May",
- "Jun",
- "July",
- "Aug",
- "Sep",
- "Oct",
- "Nov",
- "Dec",
- };
- years = new String[26];
- for (int i = 0; i <= 25; i++) {
- dates[i] = Integer.toString(i);
- years[i] = Integer.toString(1995 + i);
- }
- dayComboBox = new JComboBox<>(dates);
- dayComboBox.setBounds(160, 150, 50, 30);
- c.add(dayComboBox);
- monthComboBox = new JComboBox<>(months);
- monthComboBox.setBounds(220, 150, 60, 30);
- c.add(monthComboBox);
- yearComboBox = new JComboBox<>(years);
- yearComboBox.setBounds(290, 150, 70, 30);
- c.add(yearComboBox);
- // Class Field
- classLabel = new JLabel("Class:");
- classLabel.setBounds(50, 190, 100, 30);
- c.add(classLabel);
- classField = new JTextField();
- classField.setBounds(160, 190, 200, 30);
- c.add(classField);
- // Register Button
- registerButton = new JButton("Register");
- registerButton.setBounds(160, 230, 100, 40);
- c.add(registerButton);
- // Registration Data Display
- textArea = new JTextArea(10, 40);
- textArea.setBounds(50, 300, 400, 200);
- textArea.setEditable(false);
- c.add(textArea);
- // Action Listener for Register Button
- registerButton.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String name = nameField.getText();
- String rollNumber = rollNumberField.getText();
- String dob =
- dayComboBox.getSelectedItem() +
- " " +
- monthComboBox.getSelectedItem() +
- " " +
- yearComboBox.getSelectedItem();
- String className = classField.getText();
- String registrationData =
- "Name: " +
- name +
- "\nRoll Number: " +
- rollNumber +
- "\nDate of Birth: " +
- dob +
- "\nClass: " +
- className +
- "\n\n";
- textArea.append(registrationData);
- // Clear the input fields
- nameField.setText("");
- rollNumberField.setText("");
- dayComboBox.setSelectedIndex(0);
- monthComboBox.setSelectedIndex(0);
- yearComboBox.setSelectedIndex(0);
- classField.setText("");
- }
- }
- );
- }
- }
- public class StudentRegistrationForm {
- public static void main(String[] args) {
- MyFrame frame = new MyFrame();
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement