0% found this document useful (0 votes)
4 views14 pages

Java Assignment 7

The document describes the development of a Student Management System (SMS) using Java Swing, designed to assist school staff in managing student records, course enrollments, and grades through a user-friendly graphical interface. Key features include adding and updating student information, dynamic interface updates, and robust error handling. The system's architecture is modular, separating data management from the user interface to enhance maintainability and ease of use.

Uploaded by

Isaac Lartey
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)
4 views14 pages

Java Assignment 7

The document describes the development of a Student Management System (SMS) using Java Swing, designed to assist school staff in managing student records, course enrollments, and grades through a user-friendly graphical interface. Key features include adding and updating student information, dynamic interface updates, and robust error handling. The system's architecture is modular, separating data management from the user interface to enhance maintainability and ease of use.

Uploaded by

Isaac Lartey
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

For this project, I created a Student Management System (SMS) from scratch in Java Swing.

The
application mainly helps the school staff to have a really simple and clear GUI to manage student
details, course enrollment, and grades recording. The system is event-driven and it dynamically
reflects the changes made through the interface.

System Overview

This application is a GUI system for desktop that was made using Java Swing. Swing was
selected as it offers an extensive range of GUI components and is ideal for creating interactive
desktop software in Java. The system has the following key features:

 Adding new student records

 Updating existing student information

 Viewing student details in a table

 Enrolling students into courses

 Assigning grades to students

 Automatically updating the interface after each operation

 Handling invalid inputs through error messages

Design Architecture and Class Structure


To keep the system organized and easy to maintain, I divided the application into multiple
classes. Each class has a specific responsibility, which helps separate data handling from user
interface logic.

Student Class
The Student class represents an individual student in the system.

Its main purpose is to store student-related data such as:

 Student ID

 Student name

 Enrolled course
 Assigned grade
Getter and setter methods are used to access and modify these values safely. This approach
allows the student data to remain independent of the graphical interface.

StudentManager Class
The StudentManager class is responsible for managing all student records.

It performs tasks such as:

 Storing students in an ArrayList

 Adding new students to the system

 Providing access to student data when requested by the GUI

By separating this logic from the GUI, the application becomes easier to modify and extend in
the future.

StudentManagementGUI Class
The StudentManagementGUI class contains the main graphical user interface and handles all
user interactions.

The interface uses several Swing components, including:

 JFrame for the main window

 JTable to display student records

 JButton for actions such as adding, updating, enrolling, and grading

 JTextField and JComboBox for user input

 JOptionPane for dialog boxes and error messages

This class listens for user actions through event handlers and communicates with the
StudentManager class to perform the required operations.

Main Class
Main class acts as the entry point of the application.

Upon launch, it creates the StudentManager instance and runs the GUI with
[Link](). By doing so, it guarantees that the graphical interface is properly
set up on the Event Dispatch Thread.
Event Handling
The application follows an event-driven programming model. User actions such as clicking
buttons trigger specific methods that perform the required tasks.

For example:

 Clicking the Add Student button opens a form for entering student details

 Selecting a student and clicking Update Student allows the administrator to modify the
student’s name

 Clicking Enroll Course or Assign Grade updates the selected student’s records

Each button is connected to an ActionListener, ensuring that the system responds immediately to
user input.

Dynamic Interface Updates


The GUI updates dynamically by a table refresh mechanism. The table model is first cleared and
then filled with updated data, after each operation (adding a student, enrolling a course, or
assigning a grade).This ensures that:

 Changes are visible immediately

 No manual refresh or restart is required

 The displayed data always reflects the current system state

Error Handling and Validation


To improve usability and system stability, I implemented several error-handling measures:

 The system prevents adding students with empty input fields

 Error messages are displayed if no student is selected for an operation

 Dialog boxes clearly inform the user about incorrect actions

These checks help prevent invalid operations and guide administrators toward correct usage.

Design Decisions and Rationale


Several design choices were made to balance simplicity and functionality:
 Java Swing was chosen for its reliability and academic relevance

 Separating the application into multiple classes improves readability and maintainability

 Dialog-based forms reduce interface clutter and make interactions clearer

 Using a table (JTable) provides a structured and easy-to-read view of student records

Overall, the design focuses on clarity, ease of use, and efficient data management.

Conclusion
To sum up, the Student Management System GUI application has been able to meet the project
requirements quite well. It offers easy-to-use and fast interfaces for the management of student
records, enables course registration and grading, reflects changes instantly, and is robust in error
handling. Besides, the modular architecture helps in quick comprehension and smooth extension
of the system for the future enhancement.

References
Oracle. (2023). The Java™ Tutorials: Swing. [Link]

Oracle. (2023). Event Handling in Swing. [Link]

Eck, D. J. (2020). Introduction to Programming Using Java, Version 11.


[Link]

Schildt, H. (2018). Java: The Complete Reference (11th ed.). McGraw-Hill Education.
The Code
import [Link].*;
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;

public class StudentManagementSystem extends JFrame {

// Data storage
private ArrayList<Student> students = new ArrayList<>();
private String[] courses = {"Math", "Computer Science", "Economics", "Physics"};

// GUI components
private JTable studentTable;
private DefaultTableModel tableModel;

public StudentManagementSystem() {
setTitle("Student Management System");
setSize(900, 500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new BorderLayout());

// Table setup
tableModel = new DefaultTableModel(
new String[]{"ID", "Name", "Course", "Grade"}, 0
);
studentTable = new JTable(tableModel);
add(new JScrollPane(studentTable), [Link]);

// Buttons panel
JPanel buttonPanel = new JPanel();

JButton addBtn = new JButton("Add Student");


JButton updateBtn = new JButton("Update Student");
JButton enrollBtn = new JButton("Enroll Course");
JButton gradeBtn = new JButton("Assign Grade");

[Link](addBtn);
[Link](updateBtn);
[Link](enrollBtn);
[Link](gradeBtn);

add(buttonPanel, [Link]);

// Event handling
[Link](e -> addStudent());
[Link](e -> updateStudent());
[Link](e -> enrollCourse());
[Link](e -> assignGrade());
}

// ---------------- Student Functions ----------------

private void addStudent() {


JTextField idField = new JTextField();
JTextField nameField = new JTextField();

Object[] form = {
"Student ID:", idField,
"Student Name:", nameField
};

int option = [Link](


this, form, "Add Student", JOptionPane.OK_CANCEL_OPTION
);

if (option == JOptionPane.OK_OPTION) {
if ([Link]().isEmpty() || [Link]().isEmpty()) {
showError("All fields must be filled.");
return;
}

Student s = new Student(


[Link](),
[Link]()
);
[Link](s);
refreshTable();
}
}

private void updateStudent() {


int row = [Link]();
if (row == -1) {
showError("Please select a student to update.");
return;
}

Student s = [Link](row);
JTextField nameField = new JTextField([Link]);

Object[] form = {
"Update Name:", nameField
};

int option = [Link](


this, form, "Update Student", JOptionPane.OK_CANCEL_OPTION
);

if (option == JOptionPane.OK_OPTION) {
[Link] = [Link]();
refreshTable();
}
}

private void enrollCourse() {


int row = [Link]();
if (row == -1) {
showError("Select a student first.");
return;
}

JComboBox<String> courseBox = new JComboBox<>(courses);

int option = [Link](


this, courseBox, "Enroll Course", JOptionPane.OK_CANCEL_OPTION
);

if (option == JOptionPane.OK_OPTION) {
[Link](row).course = (String) [Link]();
refreshTable();
}
}

private void assignGrade() {


int row = [Link]();
if (row == -1) {
showError("Select a student first.");
return;
}

JTextField gradeField = new JTextField();

int option = [Link](


this, gradeField, "Assign Grade", JOptionPane.OK_CANCEL_OPTION
);

if (option == JOptionPane.OK_OPTION) {
[Link](row).grade = [Link]();
refreshTable();
}
}

// ---------------- Utility Methods ----------------

private void refreshTable() {


[Link](0);
for (Student s : students) {
[Link](new Object[]{
[Link],
[Link],
[Link] == null ? "Not Enrolled" : [Link],
[Link] == null ? "-" : [Link]
});
}
}

private void showError(String msg) {


[Link](
this, msg, "Error", JOptionPane.ERROR_MESSAGE
);
}

// ---------------- Main ----------------

public static void main(String[] args) {


[Link](() ->
new StudentManagementSystem().setVisible(true)
);
}
}

// ---------------- Student Class ----------------

class Student {
String id;
String name;
String course;
String grade;
Student(String id, String name) {
[Link] = id;
[Link] = name;
}
}

You might also like