Advertisement
vvccs

E10_StudentReg.

Nov 8th, 2023 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.27 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. class MyFrame extends JFrame {
  6.  
  7.   private Container c;
  8.   private JLabel title;
  9.   private String[] dates;
  10.   private String[] months;
  11.   private String[] years;
  12.  
  13.   private JLabel nameLabel;
  14.   private JTextField nameField;
  15.  
  16.   private JLabel rollNumberLabel;
  17.   private JTextField rollNumberField;
  18.  
  19.   private JLabel dobLabel;
  20.   private JComboBox<String> dayComboBox;
  21.   private JComboBox<String> monthComboBox;
  22.   private JComboBox<String> yearComboBox;
  23.  
  24.   private JLabel classLabel;
  25.   private JTextField classField;
  26.  
  27.   private JButton registerButton;
  28.  
  29.   private JTextArea textArea;
  30.  
  31.   public MyFrame() {
  32.     setTitle("Registration Form:");
  33.     setBounds(300, 90, 900, 700);
  34.     setDefaultCloseOperation(EXIT_ON_CLOSE);
  35.     setResizable(false);
  36.  
  37.     c = getContentPane();
  38.     c.setLayout(null);
  39.  
  40.     // Title
  41.     title = new JLabel("Registration Form:");
  42.     title.setSize(300, 30);
  43.     title.setLocation(300, 30);
  44.     c.add(title);
  45.  
  46.     // Name Field
  47.     nameLabel = new JLabel("Name:");
  48.     nameLabel.setBounds(50, 70, 100, 30);
  49.     c.add(nameLabel);
  50.     nameField = new JTextField();
  51.     nameField.setBounds(160, 70, 200, 30);
  52.     c.add(nameField);
  53.  
  54.     // Roll Number Field
  55.     rollNumberLabel = new JLabel("Roll Number:");
  56.     rollNumberLabel.setBounds(50, 110, 100, 30);
  57.     c.add(rollNumberLabel);
  58.     rollNumberField = new JTextField();
  59.     rollNumberField.setBounds(160, 110, 200, 30);
  60.     c.add(rollNumberField);
  61.  
  62.     // Date of Birth Field
  63.     dobLabel = new JLabel("Date of Birth:");
  64.     dobLabel.setBounds(50, 150, 100, 30);
  65.     c.add(dobLabel);
  66.     dates = new String[32];
  67.     months =
  68.       new String[] {
  69.         "",
  70.         "Jan",
  71.         "Feb",
  72.         "Mar",
  73.         "Apr",
  74.         "May",
  75.         "Jun",
  76.         "July",
  77.         "Aug",
  78.         "Sep",
  79.         "Oct",
  80.         "Nov",
  81.         "Dec",
  82.       };
  83.     years = new String[26];
  84.     for (int i = 0; i <= 25; i++) {
  85.       dates[i] = Integer.toString(i);
  86.       years[i] = Integer.toString(1995 + i);
  87.     }
  88.     dayComboBox = new JComboBox<>(dates);
  89.     dayComboBox.setBounds(160, 150, 50, 30);
  90.     c.add(dayComboBox);
  91.     monthComboBox = new JComboBox<>(months);
  92.     monthComboBox.setBounds(220, 150, 60, 30);
  93.     c.add(monthComboBox);
  94.     yearComboBox = new JComboBox<>(years);
  95.     yearComboBox.setBounds(290, 150, 70, 30);
  96.     c.add(yearComboBox);
  97.  
  98.     // Class Field
  99.     classLabel = new JLabel("Class:");
  100.     classLabel.setBounds(50, 190, 100, 30);
  101.     c.add(classLabel);
  102.     classField = new JTextField();
  103.     classField.setBounds(160, 190, 200, 30);
  104.     c.add(classField);
  105.  
  106.     // Register Button
  107.     registerButton = new JButton("Register");
  108.     registerButton.setBounds(160, 230, 100, 40);
  109.     c.add(registerButton);
  110.  
  111.     // Registration Data Display
  112.     textArea = new JTextArea(10, 40);
  113.     textArea.setBounds(50, 300, 400, 200);
  114.     textArea.setEditable(false);
  115.     c.add(textArea);
  116.  
  117.     // Action Listener for Register Button
  118.     registerButton.addActionListener(
  119.       new ActionListener() {
  120.         @Override
  121.         public void actionPerformed(ActionEvent e) {
  122.           String name = nameField.getText();
  123.           String rollNumber = rollNumberField.getText();
  124.           String dob =
  125.             dayComboBox.getSelectedItem() +
  126.             " " +
  127.             monthComboBox.getSelectedItem() +
  128.             " " +
  129.             yearComboBox.getSelectedItem();
  130.           String className = classField.getText();
  131.  
  132.           String registrationData =
  133.             "Name: " +
  134.             name +
  135.             "\nRoll Number: " +
  136.             rollNumber +
  137.             "\nDate of Birth: " +
  138.             dob +
  139.             "\nClass: " +
  140.             className +
  141.             "\n\n";
  142.           textArea.append(registrationData);
  143.  
  144.           // Clear the input fields
  145.           nameField.setText("");
  146.           rollNumberField.setText("");
  147.           dayComboBox.setSelectedIndex(0);
  148.           monthComboBox.setSelectedIndex(0);
  149.           yearComboBox.setSelectedIndex(0);
  150.           classField.setText("");
  151.         }
  152.       }
  153.     );
  154.   }
  155. }
  156.  
  157. public class StudentRegistrationForm {
  158.  
  159.   public static void main(String[] args) {
  160.     MyFrame frame = new MyFrame();
  161.     frame.setVisible(true);
  162.   }
  163. }
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement