student result management system in java

introduction
The student result management system in java is a robust Java application with a graphical user interface (GUI) that helps manage student data within an educational institution.
Admins can add, view, edit, or delete student records including name, roll number, department, year of study, and academic performance. The system ensures easy navigation through menus and buttons, making it beginner-friendly.
Features include student search, grade calculation, attendance tracking, and record export options. By automating manual processes like record keeping and performance tracking, the system improves accuracy and accessibility.
It is especially useful in schools, colleges, and coaching centers that require a simple yet effective way to manage student information.
steps to create student result management system in java
-
Define student attributes — ID, name, department, grades.
-
Design GUI: forms for add/edit student, search functionality.
-
Create Student class and list to hold students.
-
Implement file-based or DB storage.
-
Add features for attendance and grade calculation.
-
Integrate frontend and backend.
-
Test CRUD operations and search.
-
Add export to CSV functionality.
-
Document usage and code.
-
Compile to executable.
code explanation
1. Login Panel
usernameField, passwordField
Basic login screen.
Accepts a username and password.
If username =
"admin"
and password ="1234"
, it opens the main panel.Otherwise, it shows an “Invalid credentials” message.
2. Main Panel (After Login)
Inputs:
nameField
→ Student's NamerollField
→ Roll NumbermathField
,scienceField
,englishField
→ Marks input fields
Buttons:
Calculate Result
→ Computes total, percentage, and result.Save Result
→ Saves result to a file.View All Results
→ Reads and shows all saved results from the file.
Text Area:
resultArea
→ Displays the calculated result (total, percentage, and pass/fail).
Key Methods Explained:
🔹 calculateResult()
Reads marks from the fields.
Calculates total marks, percentage, and checks if percentage ≥ 40% (Pass).
Shows the result in the
resultArea
.
🔹 saveResult()
Saves student name, roll no, and result into a text file called
results.txt
.Checks if all fields are filled first.
Appends data to the file.
🔹 viewResults()
Reads all results saved in
results.txt
.Displays them in the
resultArea
.
🔹 clearFields()
Clears all input fields after saving.
How to Run It:
Compile and run the program.
On the login screen:
Username:
admin
Password:
1234
After logging in:
Enter name, roll no, and marks.
Click
Calculate Result
.Then click
Save Result
orView All Results
.
source code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class StudentResultManagement extends JFrame {
private JTextField usernameField, passwordField;
private JPanel loginPanel, mainPanel;
private CardLayout cardLayout;
private JTextField nameField, rollField, mathField, scienceField, englishField;
private JTextArea resultArea;
public StudentResultManagement() {
setTitle("Student Result Management System");
setSize(600, 500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
cardLayout = new CardLayout();
setLayout(cardLayout);
loginPanel = createLoginPanel();
mainPanel = createMainPanel();
add(loginPanel, "login");
add(mainPanel, "main");
cardLayout.show(getContentPane(), "login");
setVisible(true);
}
private JPanel createLoginPanel() {
JPanel panel = new JPanel(null);
JLabel label = new JLabel("Login", JLabel.CENTER);
label.setFont(new Font("Arial", Font.BOLD, 24));
label.setBounds(200, 40, 200, 40);
panel.add(label);
JLabel userLabel = new JLabel("Username:");
userLabel.setBounds(150, 120, 100, 30);
panel.add(userLabel);
usernameField = new JTextField();
usernameField.setBounds(250, 120, 150, 30);
panel.add(usernameField);
JLabel passLabel = new JLabel("Password:");
passLabel.setBounds(150, 170, 100, 30);
panel.add(passLabel);
passwordField = new JTextField(); // changed to JTextField for simplicity
passwordField.setBounds(250, 170, 150, 30);
panel.add(passwordField);
JButton loginBtn = new JButton("Login");
loginBtn.setBounds(250, 220, 150, 35);
loginBtn.addActionListener(e -> {
String user = usernameField.getText();
String pass = passwordField.getText();
if (user.equals("admin") && pass.equals("1234")) {
cardLayout.show(getContentPane(), "main");
} else {
JOptionPane.showMessageDialog(this, "Invalid credentials!");
}
});
panel.add(loginBtn);
return panel;
}
private JPanel createMainPanel() {
JPanel panel = new JPanel(null);
JLabel title = new JLabel("Enter Student Details", JLabel.CENTER);
title.setFont(new Font("Arial", Font.BOLD, 20));
title.setBounds(150, 10, 300, 40);
panel.add(title);
JLabel nameLabel = new JLabel("Name:");
nameLabel.setBounds(50, 70, 100, 30);
panel.add(nameLabel);
nameField = new JTextField();
nameField.setBounds(150, 70, 150, 30);
panel.add(nameField);
JLabel rollLabel = new JLabel("Roll No:");
rollLabel.setBounds(350, 70, 100, 30);
panel.add(rollLabel);
rollField = new JTextField();
rollField.setBounds(450, 70, 100, 30);
panel.add(rollField);
JLabel mathLabel = new JLabel("Maths Marks:");
mathLabel.setBounds(50, 120, 100, 30);
panel.add(mathLabel);
mathField = new JTextField();
mathField.setBounds(150, 120, 150, 30);
panel.add(mathField);
JLabel sciLabel = new JLabel("Science Marks:");
sciLabel.setBounds(350, 120, 100, 30);
panel.add(sciLabel);
scienceField = new JTextField();
scienceField.setBounds(450, 120, 100, 30);
panel.add(scienceField);
JLabel engLabel = new JLabel("English Marks:");
engLabel.setBounds(50, 170, 100, 30);
panel.add(engLabel);
englishField = new JTextField();
englishField.setBounds(150, 170, 150, 30);
panel.add(englishField);
JButton calcBtn = new JButton("Calculate Result");
calcBtn.setBounds(200, 220, 180, 40);
calcBtn.addActionListener(e -> calculateResult());
panel.add(calcBtn);
JButton saveBtn = new JButton("Save Result");
saveBtn.setBounds(200, 270, 180, 40);
saveBtn.addActionListener(e -> saveResult());
panel.add(saveBtn);
JButton viewBtn = new JButton("View All Results");
viewBtn.setBounds(200, 320, 180, 40);
viewBtn.addActionListener(e -> viewResults());
panel.add(viewBtn);
resultArea = new JTextArea();
resultArea.setEditable(false);
JScrollPane scroll = new JScrollPane(resultArea);
scroll.setBounds(50, 370, 500, 80);
panel.add(scroll);
return panel;
}
private void calculateResult() {
try {
int math = Integer.parseInt(mathField.getText());
int science = Integer.parseInt(scienceField.getText());
int english = Integer.parseInt(englishField.getText());
int total = math + science + english;
double percent = total / 3.0;
String grade = (percent >= 40) ? "Pass" : "Fail";
resultArea.setText("Total: " + total + "\nPercentage: " + String.format("%.2f", percent) + "%\nResult: " + grade);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Please enter valid numeric marks.");
}
}
private void saveResult() {
String name = nameField.getText().trim();
String roll = rollField.getText().trim();
String resultText = resultArea.getText();
if (name.isEmpty() || roll.isEmpty() || resultText.isEmpty()) {
JOptionPane.showMessageDialog(this, "Please fill all details and calculate result first.");
return;
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter("results.txt", true))) {
writer.write("Name: " + name + ", Roll No: " + roll + ", " + resultText.replace("\n", ", ") + "\n");
JOptionPane.showMessageDialog(this, "Result saved successfully.");
clearFields();
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error saving result.");
}
}
private void viewResults() {
try (BufferedReader reader = new BufferedReader(new FileReader("results.txt"))) {
resultArea.setText("");
String line;
while ((line = reader.readLine()) != null) {
resultArea.append(line + "\n");
}
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "No saved results found.");
}
}
private void clearFields() {
nameField.setText("");
rollField.setText("");
mathField.setText("");
scienceField.setText("");
englishField.setText("");
resultArea.setText("");
}
public static void main(String[] args) {
SwingUtilities.invokeLater(StudentResultManagement::new);
}
}
output

