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

Ex 4

Uploaded by

balagomathi003
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 views9 pages

Ex 4

Uploaded by

balagomathi003
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/ 9

Ex.

No: 04 STUDENT INFORMATION SYSTEM

Aim:
To create a student information system using java swing that collects and displays personal and academic
information across multiple tabs.

Algorithm:
Step-1: Create a window with a tabbed pane containing three tabs: one for personal information,
one for academic information, and one for summary details.

Step-2: In the personal information tab, add labeled text fields for first name, last name, and age;
radio buttons for gender selection; and checkboxes for skill selection. Add a "Next" button to navigate
to the academic information tab.

Step-3: In the academic information tab, add labeled text fields for college name and CGPA; dropdown menus
for degree and graduation year; and buttons for navigating back to the personal information tab and
forward to the summary tab.
Step-4: In the summary tab, add a text area to display the input details and a "Submit" button to finalize the
registration. Make the text area non-editable and add a scroll pane for it.
Program:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StudentInformationSystem extends JFrame implements ActionListener {
JTabbedPane tabbedPane;
JPanel personalPanel, academicPanel, finalPanel;
JTextField firstNameField, lastNameField, ageField;
JRadioButton maleButton, femaleButton, otherButton;
JCheckBox javaCheckBox, pythonCheckBox, cppCheckBox;
JComboBox<String> yearComboBox, degreeComboBox;
JTextField collegeNameField, cgpaField;
JButton nextButton1, nextButton2, backButton, submitButton;
JTextArea resultArea;
ButtonGroup genderGroup;
StudentInformationSystem() {
setTitle("Student Information System");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tabbedPane = new JTabbedPane();

// Personal Information Panel


personalPanel = new JPanel(new GridLayout(8, 2));
personalPanel.add(new JLabel("First Name:"));
firstNameField = new JTextField();
personalPanel.add(firstNameField);
personalPanel.add(new JLabel("Last Name:"));
lastNameField = new JTextField();
personalPanel.add(lastNameField);
personalPanel.add(new JLabel("Age:"));
ageField = new JTextField();
personalPanel.add(ageField);
personalPanel.add(new JLabel("Gender:"));
JPanel genderPanel = new JPanel();
maleButton = new JRadioButton("Male");
femaleButton = new JRadioButton("Female");
otherButton = new JRadioButton("Other");
genderGroup = new ButtonGroup();
genderGroup.add(maleButton);
genderGroup.add(femaleButton);
genderGroup.add(otherButton);
genderPanel.add(maleButton);
genderPanel.add(femaleButton);
genderPanel.add(otherButton);
personalPanel.add(genderPanel);
personalPanel.add(new JLabel("Skills:"));
JPanel skillsPanel = new JPanel();
javaCheckBox = new JCheckBox("Java");
pythonCheckBox = new JCheckBox("Python");
cppCheckBox = new JCheckBox("C++");
skillsPanel.add(javaCheckBox);
skillsPanel.add(pythonCheckBox);
skillsPanel.add(cppCheckBox);
personalPanel.add(skillsPanel);
nextButton1 = new JButton("Next");
nextButton1.addActionListener(this);
personalPanel.add(nextButton1);
tabbedPane.addTab("Personal Information", personalPanel);

// Academic Information Panel


academicPanel = new JPanel(new GridLayout(6, 2));
academicPanel.add(new JLabel("College Name:"));
collegeNameField = new JTextField();
academicPanel.add(collegeNameField);
academicPanel.add(new JLabel("Degree:"));
String[] degrees = {"BSc", "BA", "BCom", "BEng", "BTech", "MSc", "MA", "MCA", "MEng",
"MTech"};
degreeComboBox = new JComboBox<>(degrees);
academicPanel.add(degreeComboBox);
academicPanel.add(new JLabel("Graduation Year:"));
String[] years = {"2019","2020","2021","2022","2023","2024"};
yearComboBox = new JComboBox<>(years);
academicPanel.add(yearComboBox);
academicPanel.add(new JLabel("CGPA:"));
cgpaField = new JTextField();
academicPanel.add(cgpaField);
backButton = new JButton("Back");
backButton.addActionListener(this);
academicPanel.add(backButton);
nextButton2 = new JButton("Next");
nextButton2.addActionListener(this);
academicPanel.add(nextButton2);
tabbedPane.addTab("Academic Information", academicPanel);

// Final Panel to display details


finalPanel = new JPanel(new BorderLayout());
resultArea = new JTextArea();
resultArea.setEditable(false);
finalPanel.add(new JScrollPane(resultArea), BorderLayout.CENTER);
submitButton = new JButton("Submit");
submitButton.addActionListener(this);
finalPanel.add(submitButton, BorderLayout.SOUTH);
tabbedPane.addTab("Summary", finalPanel);
add(tabbedPane);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == nextButton1) {
tabbedPane.setSelectedIndex(1);
} else if (e.getSource() == backButton) {
tabbedPane.setSelectedIndex(0);
} else if (e.getSource() == nextButton2) {
tabbedPane.setSelectedIndex(2);
displayDetails();
} else if (e.getSource() == submitButton) {
displayDetails();
JOptionPane.showMessageDialog(this, "Registration Successful!");
}
}
private void displayDetails() {
StringBuilder personalInfo = new StringBuilder();
personalInfo.append("Personal Information:\n")
.append("First Name: ").append(firstNameField.getText()).append("\n")
.append("Last Name: ").append(lastNameField.getText()).append("\n")
.append("Age: ").append(ageField.getText()).append("\n")
.append("Gender: ");
if (maleButton.isSelected()) {
personalInfo.append("Male\n");
} else if (femaleButton.isSelected()) {
personalInfo.append("Female\n");
} else if (otherButton.isSelected()) {
personalInfo.append("Other\n");
} else {
personalInfo.append("Not specified\n"); }
personalInfo.append("Skills: ");
if (javaCheckBox.isSelected()) {
personalInfo.append("Java "); }
if (pythonCheckBox.isSelected()) {
personalInfo.append("Python "); }
if (cppCheckBox.isSelected()) {
personalInfo.append("C++ ");}
personalInfo.append("\n");
StringBuilder academicInfo = new StringBuilder();
academicInfo.append("Academic Information:\n")
.append("College Name: ").append(collegeNameField.getText()).append("\n")
.append("Degree: ").append(degreeComboBox.getSelectedItem().toString()).append("\n")
.append("Graduation Year: ").append(yearComboBox.getSelectedItem().toString()).append("\n")
.append("CGPA: ").append(cgpaField.getText()).append("\n");
resultArea.setText(personalInfo.toString() + academicInfo.toString());
}
public static void main(String[] args) {
new StudentInformationSystem();
}
}
Output:
Personal Information Tab

Academic Information Tab


Summary Tab
Result:
Thus, the student information system using java swing that collects and displays personal and
academic information across multiple tabs was executed successfully and the output was verified.

You might also like