0% found this document useful (0 votes)
22 views5 pages

JDDDD

The document is a Java program that implements a graphical user interface (GUI) for a grading system using Swing. It allows users to add students and their grades, as well as search for student records. The GUI consists of multiple panels for input fields and buttons, and it handles actions such as adding students, adding grades, and searching for records with appropriate error handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

JDDDD

The document is a Java program that implements a graphical user interface (GUI) for a grading system using Swing. It allows users to add students and their grades, as well as search for student records. The GUI consists of multiple panels for input fields and buttons, and it handles actions such as adding students, adding grades, and searching for records with appropriate error handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

import javax.swing.

*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.List;

public class GradingSystemGUI {

private JFrame frame;

private JTextField studentIdField, nameField, sectionField, subjectField,


gradeField, searchField;

private JTextArea resultArea;

private StudentDAO studentDAO = new StudentDAO();

private GradeDAO gradeDAO = new GradeDAO();

public GradingSystemGUI() {

frame = new JFrame("Grading System");

frame.setSize(700, 500);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setLayout(new BorderLayout());

JPanel panel1 = new JPanel(new FlowLayout());

studentIdField = new JTextField(10);

nameField = new JTextField(10);

sectionField = new JTextField(10);

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

panel1.add(new JLabel("Student ID:"));


panel1.add(studentIdField);

panel1.add(new JLabel("Name:"));

panel1.add(nameField);

panel1.add(new JLabel("Section:"));

panel1.add(sectionField);

panel1.add(addStudentBtn);

JPanel panel2 = new JPanel(new FlowLayout());

subjectField = new JTextField(10);

gradeField = new JTextField(5);

JButton addGradeBtn = new JButton("Add Grade");

panel2.add(new JLabel("Subject:"));

panel2.add(subjectField);

panel2.add(new JLabel("Grade:"));

panel2.add(gradeField);

panel2.add(addGradeBtn);

JPanel panel3 = new JPanel(new BorderLayout());

searchField = new JTextField(20);

JButton searchBtn = new JButton("Search");

resultArea = new JTextArea(15, 50);

resultArea.setEditable(false);

JPanel searchPanel = new JPanel(new FlowLayout());

searchPanel.add(new JLabel("Search:"));

searchPanel.add(searchField);
searchPanel.add(searchBtn);

panel3.add(searchPanel, BorderLayout.NORTH);

panel3.add(new JScrollPane(resultArea), BorderLayout.CENTER);

frame.add(panel1, BorderLayout.NORTH);

frame.add(panel2, BorderLayout.CENTER);

frame.add(panel3, BorderLayout.SOUTH);

addStudentBtn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String id = studentIdField.getText().trim();

String name = nameField.getText().trim();

String section = sectionField.getText().trim();

if (id.isEmpty() || name.isEmpty() || section.isEmpty()) {

JOptionPane.showMessageDialog(frame, "All fields are


required!", "Error", JOptionPane.ERROR_MESSAGE);

return;

studentDAO.addStudent(id, name, section);

JOptionPane.showMessageDialog(frame, "Student Added!");

studentIdField.setText("");

nameField.setText("");

sectionField.setText("");

}
});

addGradeBtn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try {

String id = studentIdField.getText().trim();

String subject = subjectField.getText().trim();

double grade = Double.parseDouble(gradeField.getText().trim());

if (id.isEmpty() || subject.isEmpty()) {

JOptionPane.showMessageDialog(frame, "Student ID and


Subject are required!", "Error", JOptionPane.ERROR_MESSAGE);

return;

gradeDAO.addGrade(id, subject, grade);

JOptionPane.showMessageDialog(frame, "Grade Added!");

subjectField.setText("");

gradeField.setText("");

} catch (NumberFormatException ex) {

JOptionPane.showMessageDialog(frame, "Invalid grade! Enter a


numeric value.", "Error", JOptionPane.ERROR_MESSAGE);

});

searchBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

resultArea.setText("");

String query = searchField.getText().trim();

List<String> students = studentDAO.searchStudent(query);

List<String> grades = gradeDAO.getGrades(query);

if (students.isEmpty() && grades.isEmpty()) {

resultArea.append("No records found.\n");

} else {

for (String s : students) resultArea.append(s + "\n");

for (String g : grades) resultArea.append(g + "\n");

});

frame.setVisible(true);

public static void main(String[] args) {

new GradingSystemGUI();

You might also like