0% found this document useful (0 votes)
20 views10 pages

Studentmanagwement

The document outlines a Java Swing application for a Student Management System, allowing users to add, edit, delete, and display student information. It features a graphical user interface with components like text fields, buttons, and a text area, and utilizes a stack to manage student records. The application includes user authentication and displays a welcome image before accessing the main functionality.

Uploaded by

vivektermix79
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)
20 views10 pages

Studentmanagwement

The document outlines a Java Swing application for a Student Management System, allowing users to add, edit, delete, and display student information. It features a graphical user interface with components like text fields, buttons, and a text area, and utilizes a stack to manage student records. The application includes user authentication and displays a welcome image before accessing the main functionality.

Uploaded by

vivektermix79
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/ 10

import javax.swing.

*;

import java.awt.*;

import java.awt.event.*;

import java.util.Date;

import java.text.SimpleDateFormat;

import java.util.Stack;

import java.util.HashSet;

class Student {

String name;

String rollNo;

int age;

String registrationDate;

public Student(String name, String rollNo, int age, String registrationDate) {

this.name = name;

this.rollNo = rollNo;

this.age = age;

this.registrationDate = registrationDate;

@Override

public String toString() {

return "Name: " + name + ", Roll No: " + rollNo + ", Age: " + age +

", Registration Date: " + registrationDate + "\n";

public class StudentManagementSystem extends JFrame implements ActionListener {


private JTextField nameField, rollField, ageField;

private JTextArea displayArea;

private JButton addButton, showButton, editButton, deleteButton, clearButton;

private Stack<Student> studentStack = new Stack<>();

private HashSet<String> rollNumbers = new HashSet<>();

// Custom JPanel for background image class BackgroundPanel extends JPanel {

private Image backgroundImage;

public BackgroundPanel() { // Load the background image backgroundImage = new


ImageIcon("bg1.jpg").getImage();

@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);

// Draw the background image to ill the entire panel

g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);

public StudentManagementSystem() {

setTitle("Student Management System");

setSize(700, 600);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setResizable(false);
// Set the background panel as content pane

BackgroundPanel backgroundPanel = new BackgroundPanel();

backgroundPanel.setLayout(null); // Set layout to null for absolute positioning


setContentPane(backgroundPanel);

// Labels

JLabel nameLabel = new JLabel("Name:");

JLabel rollLabel = new JLabel("Roll No:");

JLabel ageLabel = new JLabel("Age:");

// Set font to bold

Font boldFont = new Font("Arial", Font.BOLD, 14); // Example font with size 14

nameLabel.setFont(boldFont);

rollLabel.setFont(boldFont);

ageLabel.setFont(boldFont);

// Text Fields nameField = new JTextField(); rollField = new JTextField();

// ageField = new JTextField();

// Buttons

addButton = new JButton("Add Student");

showButton = new JButton("Show All Students");

editButton = new JButton("Edit Student");

deleteButton = new JButton("Delete Student");

clearButton = new JButton("Clear Display");

// Text Area with Scroll Pane displayArea = new JTextArea();

// displayArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(displayArea);

// Set Bounds for Components nameLabel.setBounds(50, 30, 100, 30);

nameField.setBounds(150, 30, 150, 30);

rollLabel.setBounds(50, 80, 100, 30);

rollField.setBounds(150, 80, 150, 30);

ageLabel.setBounds(50, 130, 100, 30);

ageField.setBounds(150, 130, 150, 30);

addButton.setBounds(50, 180, 120, 30);

editButton.setBounds(180, 180, 120, 30);

deleteButton.setBounds(310, 180, 120, 30);

showButton.setBounds(440, 180, 150, 30);

clearButton.setBounds(440, 230, 150, 30); // Clear Button

scrollPane.setBounds(50, 280, 600, 250);

// Adding Components to the background panel backgroundPanel.add(nameLabel);

// backgroundPanel.add(nameField); backgroundPanel.add(rollLabel);

// backgroundPanel.add(rollField); backgroundPanel.add(ageLabel);

// backgroundPanel.add(ageField); backgroundPanel.add(addButton);

// backgroundPanel.add(editButton); backgroundPanel.add(deleteButton);

// backgroundPanel.add(showButton); backgroundPanel.add(clearButton);

backgroundPanel.add(scrollPane);

// Adding Action Listeners addButton.addActionListener(this);

// showButton.addActionListener(this); editButton.addActionListener(this);
// deleteButton.addActionListener(this);

clearButton.addActionListener(this);

// Set color #ffae42 (orange) for labels and their associated text boxes

// Set label colors

nameLabel.setForeground(Color.decode("#ffed29"));

rollLabel.setForeground(Color.decode("#ffed29"));

ageLabel.setForeground(Color.decode("#ffed29"));

// Set text ield background colors nameField.setBackground(Color.WHITE);

// rollField.setBackground(Color.WHITE); ageField.setBackground(Color.WHITE);

// Optional: You can also set the text color to contrast better with the

// background nameField.setForeground(Color.black);

// rollField.setForeground(Color.black); ageField.setForeground(Color.black);

// Button background colors addButton.setBackground(Color.GREEN);

// editButton.setBackground(Color.CYAN); deleteButton.setBackground(Color.RED);

// showButton.setBackground(Color.YELLOW);

clearButton.setBackground(Color.LIGHT_GRAY); // Light Blue Color

displayArea.setBackground(Color.decode("#add8e6"));

displayArea.setForeground(Color.black);

@Override

public void actionPerformed(ActionEvent e) {

String rollNo = rollField.getText().trim();


if (e.getSource() == addButton) {

if (rollNumbers.contains(rollNo)) {

JOptionPane.showMessageDialog(this, "Error: Roll No already exists!");

return;

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

int age = Integer.parseInt(ageField.getText().trim());

String registrationDate = new SimpleDateFormat("dd/MM/yyyy").format(new Date());

studentStack.push(new Student(name, rollNo, age, registrationDate));

rollNumbers.add(rollNo);

nameField.setText("");

rollField.setText("");

ageField.setText("");

JOptionPane.showMessageDialog(this, "Student added successfully!");

} else if (e.getSource() == showButton) {

if (studentStack.isEmpty()) {

displayArea.setText("No students registered yet.");

} else {

StringBuilder studentDetails = new StringBuilder();

for (Student student : studentStack) {

studentDetails.append(student.toString());

displayArea.setText(studentDetails.toString());

} else if (e.getSource() == editButton) {


Student studentToEdit = indStudentByRollNo(rollNo);

if (studentToEdit != null) {

String newName = JOptionPane.showInputDialog(this, "Enter new name:",


studentToEdit.name);

int newAge = Integer.parseInt(JOptionPane.showInputDialog(this, "Enter new age:",

studentToEdit.age));

studentToEdit.name = newName;

studentToEdit.age = newAge;

JOptionPane.showMessageDialog(this, "Student information updated.");

} else {

JOptionPane.showMessageDialog(this, "Error: Student not found!");

} else if (e.getSource() == deleteButton) {

boolean removed = deleteStudentByRollNo(rollNo);

if (removed) {

JOptionPane.showMessageDialog(this, "Student deleted.");

} else {

JOptionPane.showMessageDialog(this, "Error: Student not found!");

} else if (e.getSource() == clearButton) {

displayArea.setText(""); // Clear the display area

private Student indStudentByRollNo(String rollNo) {

for (Student student : studentStack) {

if (student.rollNo.equals(rollNo)) {

return student;
}

return null;

private boolean deleteStudentByRollNo(String rollNo) {

Stack<Student> tempStack = new Stack<>();

boolean found = false;

while (!studentStack.isEmpty()) {

Student student = studentStack.pop();

if (student.rollNo.equals(rollNo)) {

rollNumbers.remove(rollNo);

found = true;

break;

} else {

tempStack.push(student);

while (!tempStack.isEmpty()) {

studentStack.push(tempStack.pop());

return found;

public static void main(String[] args) {

String username = JOptionPane.showInputDialog("Enter Username:");

String password = JOptionPane.showInputDialog("Enter Password:");


if (username.equals("admin") && password.equals("1234")) {

// Create a new JFrame for displaying the image JFrame imageFrame = new

// JFrame("Welcome");

imageFrame.setSize(400, 300);

imageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

imageFrame.setLayout(new BorderLayout());

// Load the image

ImageIcon icon = new ImageIcon("ok.jpeg");

JLabel label = new JLabel(icon);

imageFrame.add(label, BorderLayout.CENTER);

// Create a JLabel for the "Please wait" message

JLabel waitMessage = new JLabel("Please wait...", SwingConstants.CENTER);

waitMessage.setFont(new Font("Times New Roman", Font.BOLD, 24));

waitMessage.setForeground(Color.RED); // Set the color of the message


imageFrame.add(waitMessage,

// BorderLayout.SOUTH); // Add the message below the image

// Show the frame

imageFrame.setVisible(true);

// Close the image frame after 3 seconds and open the main system window

Timer timer = new Timer(3000, new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

imageFrame.dispose(); // Close the image frame


// Open the main system window

StudentManagementSystem sms = new StudentManagementSystem();

sms.setVisible(true);

});

timer.setRepeats(false); // Ensure the timer only runs once timer.start();

} else {

JOptionPane.showMessageDialog(null, "Invalid login credentials!", "Error",

JOptionPane.ERROR_MESSAGE);

You might also like