请写一个Java学生信息管理系统代码要求要连接数据库有登录注册界面并且要有添加学生信息删除学生信息修改学生信息这些都是单独的功能界面

请写一个Java学生信息管理系统代码要求要连接数据库有登录注册界面并且要有添加学生信息删除学生信息修改学生信息这些都是单独的功能界面
由于涉及到用户界面和数据库操作,代码较长,以下仅提供参考:

  1. 登录界面

import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.sql.
;

public class Login extends JFrame implements ActionListener {

private JLabel label1, label2, label3;
private JTextField text1;
private JPasswordField text2;
private JButton button1, button2;

public Login() {
    setTitle("学生信息管理系统 - 登录");
    setSize(300, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setResizable(false);

    Container container = getContentPane();
    container.setLayout(new GridLayout(3, 2));

    label1 = new JLabel("用户名:");
    label2 = new JLabel("密码:");
    label3 = new JLabel("");
    text1 = new JTextField();
    text2 = new JPasswordField();
    button1 = new JButton("登录");
    button2 = new JButton("注册");

    button1.addActionListener(this);
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new Register();
        }
    });

    container.add(label1);
    container.add(text1);
    container.add(label2);
    container.add(text2);
    container.add(button1);
    container.add(button2);

    setLocationRelativeTo(null);
    setVisible(true);
}

public void actionPerformed(ActionEvent e) {
    String username = text1.getText().trim();
    String password = new String(text2.getPassword()).trim();
    if (username.equals("") || password.equals("")) {
        label3.setText("用户名或密码不能为空!");
        return;
    }
    try {
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "password");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM user WHERE username='" + username + "' AND password='" + password + "'");
        if (rs.next()) {
            new Main();
            dispose();
        } else {
            label3.setText("用户名或密码错误!");
        }
        rs.close();
        stmt.close();
        con.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

public static void main(String[] args) {
    new Login();
}

}

  1. 注册界面

import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.sql.
;

public class Register extends JFrame implements ActionListener {

private JLabel label1, label2, label3, label4;
private JTextField text1, text2;
private JPasswordField text3, text4;
private JButton button1, button2;

public Register() {
    setTitle("学生信息管理系统 - 注册");
    setSize(300, 200);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setResizable(false);

    Container container = getContentPane();
    container.setLayout(new GridLayout(5, 2));

    label1 = new JLabel("用户名:");
    label2 = new JLabel("密码:");
    label3 = new JLabel("确认密码:");
    label4 = new JLabel("");
    text1 = new JTextField();
    text2 = new JTextField();
    text3 = new JPasswordField();
    text4 = new JPasswordField();
    button1 = new JButton("注册");
    button2 = new JButton("取消");

    button1.addActionListener(this);
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    container.add(label1);
    container.add(text1);
    container.add(label2);
    container.add(text3);
    container.add(label3);
    container.add(text4);
    container.add(button1);
    container.add(button2);
    container.add(label4);

    setLocationRelativeTo(null);
    setVisible(true);
}

public void actionPerformed(ActionEvent e) {
    String username = text1.getText().trim();
    String password = new String(text3.getPassword()).trim();
    String confirm = new String(text4.getPassword()).trim();
    if (username.equals("") || password.equals("") || confirm.equals("")) {
        label4.setText("用户名或密码不能为空!");
        return;
    } else if (!password.equals(confirm)) {
        label4.setText("两次输入的密码不一致!");
        return;
    }
    try {
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "password");
        Statement stmt = con.createStatement();
        stmt.executeUpdate("INSERT INTO user(username, password) VALUES('" + username + "', '" + password + "')");
        stmt.close();
        con.close();
        JOptionPane.showMessageDialog(null, "注册成功!");
        dispose();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

}

  1. 主界面

import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.sql.
;

public class Main extends JFrame implements ActionListener {

private JMenuBar menubar;
private JMenu menu1, menu2, menu3;
private JMenuItem item1, item2, item3, item4, item5;
private JPanel panel1, panel2;
private JLabel label1, label2, label3, label4, label5;
private JTextField text1, text2, text3, text4, text5;
private JButton button1, button2, button3, button4;
private JTable table1;
private JScrollPane scrollpane1;
private DefaultTableModel model;

public Main() {
    setTitle("学生信息管理系统 - 主界面");
    setSize(600, 400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setResizable(false);

    menubar = new JMenuBar();
    menu1 = new JMenu("学生信息");
    menu2 = new JMenu("添加信息");
    menu3 = new JMenu("用户管理");
    item1 = new JMenuItem("查询信息");
    item2 = new JMenuItem("修改信息");
    item3 = new JMenuItem("删除信息");
    item4 = new JMenuItem("添加学生信息");
    item5 = new JMenuItem("修改密码");
    panel1 = new JPanel();
    panel2 = new JPanel();
    label1 = new JLabel("学号:");
    label2 = new JLabel("姓名:");
    label3 = new JLabel("性别:");
    label4 = new JLabel("年龄:");
    label5 = new JLabel("专业:");
    text1 = new JTextField(10);
    text2 = new JTextField(10);
    text3 = new JTextField(10);
    text4 = new JTextField(10);
    text5 = new JTextField(10);
    button1 = new JButton("添加");
    button2 = new JButton("删除");
    button3 = new JButton("修改");
    button4 = new JButton("查询");
    model = new DefaultTableModel();
    table1 = new JTable(model);
    scrollpane1 = new JScrollPane(table1);

    item1.addActionListener(this);
    item2.addActionListener(this);
    item3.addActionListener(this);
    item4.addActionListener(this);
    item5.addActionListener(this);
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    button4.addActionListener(this);

    menu1.add(item1);
    menu1.add(item2);
    menu1.add(item3);
    menu2.add(item4);
    menu3.add(item5);
    menubar.add(menu1);
    menubar.add(menu2);
    menubar.add(menu3);
    setJMenuBar(menubar);

    panel1.setLayout(new GridLayout(5, 2));
    panel1.add(label1);
    panel1.add(text1);
    panel1.add(label2);
    panel1.add(text2);
    panel1.add(label3);
    panel1.add(text3);
    panel1.add(label4);
    panel1.add(text4);
    panel1.add(label5);
    panel1.add(text5);
    panel1.setBorder(BorderFactory.createTitledBorder("添加信息"));

    panel2.setLayout(new FlowLayout());
    panel2.add(button1);
    panel2.add(button2);
    panel2.add(button3);
    panel2.add(button4);

    model.addColumn("学号");
    model.addColumn("姓名");
    model.addColumn("性别");
    model.addColumn("年龄");
    model.addColumn("专业");

    Container container = getContentPane();
    container.setLayout(new BorderLayout());
    container.add(panel1, BorderLayout.NORTH);
    container.add(panel2, BorderLayout.CENTER);
    container.add(scrollpane1, BorderLayout.SOUTH);

    setLocationRelativeTo(null);
    setVisible(true);
}

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == item1) {
        new Query();
    } else if (e.getSource() == item2) {
        new Modify();
    } else if (e.getSource() == item3) {
        new Delete();
    } else if (e.getSource() == item4) {
        text1.setText("");
        text2.setText("");
        text3.setText("");
        text4.setText("");
        text5.setText("");
        model.setRowCount(0);
    } else if (e.getSource() == item5) {
        new ChangePassword();
    } else if (e.getSource() == button1) {
        String sno = text1.getText().trim();
        String name = text2.getText().trim();
        String sex = text3.getText().trim();
        String age = text4.getText().trim();
        String major = text5.getText().trim();
        if (sno.equals("") || name.equals("") || sex.equals("") || age.equals("") || major.equals("")) {
            JOptionPane.showMessageDialog(null, "请填写完整信息!");
            return;
        }
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "password");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM student WHERE sno='" + sno + "'");
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "该学号已存在!");
                return;
            }
            stmt.executeUpdate("INSERT INTO student(sno, name, sex, age, major) VALUES('" + sno + "', '" + name + "', '" + sex + "', '" + age + "', '" + major + "')");
            JOptionPane.showMessageDialog(null, "添加成功!");
            rs.close();
            stmt.close();
            con.close();
            text1.setText("");
            text2.setText("");
            text3.setText("");
            text4.setText("");
            text5.setText("");
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    } else if (e.getSource() == button2) {
        int row = table1.getSelectedRow();
        if (row == -1) {
            JOptionPane.showMessageDialog(null, "请先选择要删除的行!");
            return;
        }
        String sno = (String)model.getValueAt(row, 0);
        int confirm = JOptionPane.showConfirmDialog(null, "确定要删除学号为 " + sno + " 的学生信息吗?", "确认删除", JOptionPane.YES_NO_OPTION);
        if (confirm == JOptionPane.YES_OPTION) {
            try {
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "password");
                Statement stmt = con.createStatement();
                stmt.executeUpdate("DELETE FROM student WHERE sno='" + sno + "'");
                model.removeRow(row);
                JOptionPane.showMessageDialog(null, "删除成功!");
                stmt.close();
                con.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    } else if (e.getSource() == button3) {
        int row = table1.getSelectedRow();
        if (row == -1) {
            JOptionPane.showMessageDialog(null, "请先选择要修改的行!");
            return;
        }
        String sno = (String)model.getValueAt(row, 0);
        String name = (String)model.getValueAt(row, 1);
        String sex = (String)model.getValueAt(row, 2);
        String age = (String)model.getValueAt(row, 3);
        String major = (String)model.getValueAt(row, 4);
        new Modify(sno, name, sex, age, major);
    } else if (e.getSource() == button4) {
        String sno = text1.getText().trim();
        String name = text2.getText().trim();
        String sex = text3.getText().trim();
        String age = text4.getText().trim();
        String major = text5.getText().trim();
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "password");
            Statement stmt = con.createStatement();
            String sql = "SELECT * FROM student WHERE 1=1";
            if (!sno.equals("")) {
                sql += " AND sno='" + sno + "'";
            }
            if (!name.equals("")) {
                sql += " AND name='" + name + "'";
            }
            if (!sex.equals("")) {
                sql += " AND sex='" + sex + "'";
            }
            if (!age.equals("")) {
                sql += " AND age='" + age + "'";
            }
            if (!major.equals("")) {
                sql += " AND major='" + major + "'";
            }
            ResultSet rs = stmt.executeQuery(sql);
            model.setRowCount(0);
            while (rs.next()) {
                String[] row = {rs.getString("sno"), rs.getString("name"), rs.getString("sex"), rs.getString("age"), rs.getString("major")};
                model.addRow(row);
            }
            rs.close();
            stmt.close();
            con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}

public static void main(String[] args) {
    new Main();
}

}

  1. 查询界面

import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.sql.
;

public class Query extends JFrame implements ActionListener {

private JLabel label1, label2, label3, label4, label5;
private JTextField text1, text2, text3, text4, text5;
private JButton button;

public Query() {
    setTitle("学生信息管理系统 - 查询信息");
    setSize(300, 200);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setResizable(false);

    Container container = getContentPane();
    container.setLayout(new GridLayout(6, 2));

    label1 = new JLabel("学号:");
    label2 = new JLabel("姓名:");
    label3 = new JLabel("性别:");
    label4 = new JLabel("年龄:");
    label5 = new JLabel("专业:");
    text1 = new JTextField();
    text2 = new JTextField();
    text3 = new JTextField();
    text4 = new JTextField();
    text5 = new JTextField();
    button = new JButton("查询");

    button.addActionListener(this);

    container.add(label1);
    container.add(text1);
    container.add(label2);
    container.add(text2);
    container.add(label3);
    container.add(text3);
    container.add(label4);
    container.add(text4);
    container.add(label5);
    container.add(text5);
    container.add(new JLabel(""));
    container.add(button);

    setLocationRelativeTo(null);
    setVisible(true);
}

public void actionPerformed(ActionEvent e) {
    String sno = text1.getText().trim();
    String name = text2.getText().trim();
    String sex = text3.getText().trim();
    String age = text4.getText().trim();
    String major = text5.getText().trim();
    try {
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "password");
        Statement stmt = con.createStatement();
        String sql = "SELECT * FROM student WHERE 1=1";
        if (!sno.equals("")) {
            sql += " AND sno='" + sno + "'";
        }
        if (!name.equals("")) {
            sql += " AND name='" + name + "'";
        }
        if (!sex.equals("")) {
            sql += " AND sex='" + sex + "'";
        }
        if (!age.equals("")) {
            sql += " AND age='" + age + "'";
        }
        if (!major.equals("")) {
            sql += " AND major='" + major + "'";
        }
        ResultSet rs = stmt.executeQuery(sql);
        if (!rs.next()) {
            JOptionPane.showMessageDialog(null, "未找到匹配的记录!");
        } else {
            String message = "";
            do {
                message += "学号:" + rs.getString("sno") + "\n";
                message += "姓名:" + rs.getString("name") + "\n";
                message += "性别:" + rs.getString("sex") + "\n";
                message += "年龄:" + rs.getString("age") + "\n";
                message += "专业:" + rs.getString("major") + "\n\n";
            } while (rs.next());
            JOptionPane.showMessageDialog(null, message);
        }
        rs.close();
        stmt.close();
        con.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

}

  1. 修改界面

import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.sql.
;

public class Modify extends JFrame implements ActionListener {

private JLabel label1, label2, label3, label4, label5;
private JTextField text1, text2, text3, text4, text5;
private JButton button1, button2;
private String sno, name, sex, age, major;

public Modify(String sno, String name, String sex, String age, String major) {
    setTitle("学生信息管理系统 - 修改信息");
    setSize(300, 200);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setResizable(false);

    this.sno = sno;
    this.name = name;
    this.sex = sex;
    this.age = age;
    this.major = major;

    Container container = getContentPane();
    container.setLayout(new GridLayout(6, 2));

    label1 = new JLabel("学号:");
    label2 = new JLabel("姓名:");
    label3 = new JLabel("性别:");
    label4 = new JLabel("年龄:");
    label5 = new JLabel("专业:");
    text1 = new JTextField(sno);
    text2 = new JTextField(name);
    text3 = new JTextField(sex);
    text4 = new JTextField(age);
    text5 = new JTextField(major);
    button1 = new JButton("修改");
    button2 = new JButton("取消");

    button1.addActionListener(this);
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    container.add(label1);
    container.add(text1);
    container.add(label2);
    container.add(text2);
    container.add(label3);
    container.add(text3);
    container.add(label4);
    container.add(text4);
    container.add(label5);
    container.add(text5);
    container.add(button1);
    container.add(button2);

    setLocationRelativeTo(null);
    setVisible(true);
}

public void actionPerformed(ActionEvent e) {
    String sno = text1.getText().trim();
    String name = text2.getText().trim();
    String sex = text3.getText().trim();
    String age = text4.getText().trim();
    String major = text5.getText().trim();
    if (sno.equals("") || name.equals("") || sex.equals("") || age.equals("") || major.equals("")) {
        JOptionPane.showMessageDialog(null, "请填写完整信息!");
        return;
    }
    try {
        Connection con =