Java swing 学生成绩管理系统

Java swing 学生成绩管理系统

ps:代码已上传网盘提取码:1111,内有JDBC的jar包,管理员登录账号:admin密码:admin

功能需求

1,学生可查自己的分数,可以选课
2,教师可以为学生输入分数
3,教师可查自己所授课相应学生的成绩
4,管理员可以对教师,学生信息的增删改查
5,用数据库存储信息

效果图

登录界面
Java swing 学生成绩管理系统_第1张图片
管理员功能选项
Java swing 学生成绩管理系统_第2张图片
管理员对教师的操作
Java swing 学生成绩管理系统_第3张图片

部分代码

连接数据库

private static Connection getConn() {
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/Information?serverTimezone=UTC";
        String username = "root";
        String password = "";
        Connection conn = null;
        try {
            Class.forName(driver); //classLoader,加载对应驱动
            conn = (Connection) DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

实体类

public class Score {
    private int id;
    private String subject;
    private String subjectTeacher;
    private String member;
    private int result;
    public Score() {
    }
    public Score(int id, String subject, String subjectTeacher, String member,int result) {
        this.id = id;
        this.subject = subject;
        this.subjectTeacher = subjectTeacher;
        this.member = member;
        this.result = result;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getSubject() {
        return subject;
    }
    public void setSubject(String subject) {
        this.subject = subject;
    }
    public String getSubjectTeacher() {
        return subjectTeacher;
    }
    public void setSubjectTeacher(String subjectTeacher) {
        this.subjectTeacher = subjectTeacher;
    }
    public String getMember() {
        return member;
    }
    public void setMember(String member) {
        this.member = member;
    }
    public int getResult() {
        return result;
    }
    public void setResult(int result) {
        this.result = result;
    }
}

登录

public class Login {
    private JFrame jFrame;
    private JPanel jPanel;
    private JLabel user;
    private JLabel password;
    private JTextField usertxt;
    private JTextField passwordtxt;
    private JButton login;
    private JButton registered;
    public static String subject;
    public static int id;
    public void show(){
        jFrame = new JFrame("学生成绩管理系统");
        jFrame.setBounds(700,200,400,300);
        jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);
        jFrame.add(panel());
        jFrame.setVisible(true);
    }
    public JPanel panel(){
        jPanel = new JPanel(null);
        user = new JLabel("用户名");
        user.setBounds(50,50,50,30);
        jPanel.add(user);
        usertxt = new JTextField();
        usertxt.setBounds(120,50,100,30);
        jPanel.add(usertxt);
        password = new JLabel("密码");
        password.setBounds(50,100,50,30);
        jPanel.add(password);
        passwordtxt = new JTextField();
        passwordtxt.setBounds(120,100,100,30);
        jPanel.add(passwordtxt);
        login = new JButton("登录");
        login.setBounds(80,150,70,30);
        jPanel.add(login);
        registered = new JButton("注册");
        registered.setBounds(170,150,70,30);
        jPanel.add(registered);
        login.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StudentInformationsql.getAll();
                TeacherInformationsql.getAll();
                String user = usertxt.getText();
                String password = passwordtxt.getText();
                for (int i = 0; i <StudentInformationsql.studata.length ; i++) {
                    //学生
                    if (user.equals(StudentInformationsql.studata[i][0]+"")&password.equals(StudentInformationsql.studata[i][4]+"")){
                        id = Integer.parseInt(user);
                        new com.window.student.Menue().show();
                        jFrame.setVisible(false);
                        break;
                        //教师
                    }else if (user.equals(TeacherInformationsql.teadata[i][0]+"")&password.equals(TeacherInformationsql.teadata[i][5]+"")){
                       subject  = TeacherInformationsql.teadata[i][2]+"";
                        new com.window.teacher.Menue().show();
                        jFrame.setVisible(false);
                        break;
                        //管理员
                    }else if (user.equals("admin")&password.equals("admin")){
                        new Menue().show();
                        jFrame.setVisible(false);
                        break;
                    }
                }
            }
        });
        registered.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new Registered().show();
            }
        });
        return jPanel;
    }
}

你可能感兴趣的:(mysql,jdbc,swing,gui,java)