0% found this document useful (0 votes)
10 views3 pages

Student Record System Java

The document describes a Student Records System implemented in Java using NetBeans. It includes two main classes: Student, which holds student information, and StudentRecordSystem, which provides a graphical user interface for adding, viewing, searching, and deleting student records. The system utilizes Swing components for user interaction and manages student data using an ArrayList.

Uploaded by

sukanyasharma211
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)
10 views3 pages

Student Record System Java

The document describes a Student Records System implemented in Java using NetBeans. It includes two main classes: Student, which holds student information, and StudentRecordSystem, which provides a graphical user interface for adding, viewing, searching, and deleting student records. The system utilizes Swing components for user interaction and manages student data using an ArrayList.

Uploaded by

sukanyasharma211
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/ 3

Student Records System in Java (NetBeans)

File: Student.java

public class Student {


private String name;
private String rollNumber;
private String course;

public Student(String name, String rollNumber, String course) {


this.name = name;
this.rollNumber = rollNumber;
this.course = course;
}

public String getName() {


return name;
}

public String getRollNumber() {


return rollNumber;
}

public String getCourse() {


return course;
}

@Override
public String toString() {
return "Roll No: " + rollNumber + ", Name: " + name + ", Course: " + course;
}
}

File: StudentRecordSystem.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

public class StudentRecordSystem extends JFrame {


private JTextField nameField, rollField, courseField;
private JTextArea displayArea;
private ArrayList<Student> studentList;

public StudentRecordSystem() {
studentList = new ArrayList<>();
setTitle("Student Record System");
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());

JPanel inputPanel = new JPanel(new GridLayout(4, 2));


inputPanel.add(new JLabel("Name:"));
nameField = new JTextField();
inputPanel.add(nameField);

inputPanel.add(new JLabel("Roll No:"));


rollField = new JTextField();
inputPanel.add(rollField);

inputPanel.add(new JLabel("Course:"));
courseField = new JTextField();
inputPanel.add(courseField);
JButton addButton = new JButton("Add Student");
inputPanel.add(addButton);

JButton searchButton = new JButton("Search");


inputPanel.add(searchButton);

add(inputPanel, BorderLayout.NORTH);

displayArea = new JTextArea();


displayArea.setEditable(false);
add(new JScrollPane(displayArea), BorderLayout.CENTER);

JPanel bottomPanel = new JPanel();


JButton viewButton = new JButton("View All");
JButton deleteButton = new JButton("Delete");

bottomPanel.add(viewButton);
bottomPanel.add(deleteButton);
add(bottomPanel, BorderLayout.SOUTH);

addButton.addActionListener(e -> addStudent());


viewButton.addActionListener(e -> viewStudents());
searchButton.addActionListener(e -> searchStudent());
deleteButton.addActionListener(e -> deleteStudent());

setVisible(true);
}

private void addStudent() {


String name = nameField.getText();
String roll = rollField.getText();
String course = courseField.getText();

if (!name.isEmpty() && !roll.isEmpty() && !course.isEmpty()) {


studentList.add(new Student(name, roll, course));
displayArea.setText("Student added successfully.\n");
nameField.setText("");
rollField.setText("");
courseField.setText("");
} else {
displayArea.setText("Please fill all fields.\n");
}
}

private void viewStudents() {


displayArea.setText("");
for (Student s : studentList) {
displayArea.append(s.toString() + "\n");
}
}

private void searchStudent() {


String roll = JOptionPane.showInputDialog(this, "Enter Roll No to search:");
boolean found = false;

for (Student s : studentList) {


if (s.getRollNumber().equals(roll)) {
displayArea.setText("Student Found:\n" + s.toString());
found = true;
break;
}
}

if (!found) {
displayArea.setText("Student not found.\n");
}
}

private void deleteStudent() {


String roll = JOptionPane.showInputDialog(this, "Enter Roll No to delete:");
boolean removed = studentList.removeIf(s -> s.getRollNumber().equals(roll));

if (removed) {
displayArea.setText("Student deleted.\n");
} else {
displayArea.setText("Student not found.\n");
}
}

public static void main(String[] args) {


new StudentRecordSystem();
}
}

You might also like