Java+Eclipse+MySQL+Swing实现学生会考成绩管理系统(免费完整项目)

版权声明:原创不易,本文禁止抄袭、转载,侵权必究!

一、需求开发文档

项目完整文件列表:
在这里插入图片描述
需求开发文档部分截图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、数据库设计文档

数据库设计文档部分截图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

三、功能模块部分代码及效果展示

数据库类:

package system_of_database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
    
    

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    public Connection getConnection() throws ClassNotFoundException,
            SQLException,InstantiationException,IllegalAccessException {
    
    
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/exam_of_students?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
        String user = "root";
        String password = "root";
        try {
    
    
            Class.forName(driver);
            con = DriverManager.getConnection(url,user,password);
            return con;
        } catch(Exception e) {
    
    
            throw new SQLException("驱动错误或连接失败!");
        }
    }

考生登录部分代码如下:
public class LoginListener implements ActionListener{
    
    
        public void actionPerformed(ActionEvent e) {
    
    
            lblMsg1.setText("");
            lblMsg2.setText("");
            user = userService.findUserByName(txtName.getText().trim());
            if(user != null) {
    
    
                if(user.getPassword().equals(new String(txtPwd.getPassword()))) {
    
    
                    LoginFrame_Of_Students.this.setVisible(false);
                    new MainFrame_Of_Students();
                } else {
    
    
                    lblMsg2.setText("密码错误!");
                    txtPwd.setText("");
                }
            } else {
    
    
                lblMsg1.setText("该考生不存在 !");
            }
        }
    }

考生登录效果如下:
在这里插入图片描述

管理员登录部分代码如下:

public class LoginListener implements ActionListener{
    
    
        public void actionPerformed(ActionEvent e) {
    
    
            lblMsg1.setText("");
            lblMsg2.setText("");
            user = userService.findUserByName(txtName.getText().trim());
            if(user != null) {
    
    
                if(user.getPassword().equals(new String(txtPwd.getPassword()))) {
    
    
                    LoginFrame_Of_Administration.this.setVisible(false);
                    new MainFrame_Of_Administration();
                } else {
    
    
                    lblMsg2.setText("密码错误!");
                    txtPwd.setText("");
                }
            } else {
    
    
                lblMsg1.setText("该管理员不存在 !");
            }
        }
    }

    public class ResetListener implements ActionListener{
    
    
        public void actionPerformed(ActionEvent e) {
    
    
            txtName.setText("");
            txtPwd.setText("");
        }
    }

管理员登录效果如下:
在这里插入图片描述
考生查询成绩部分代码如下:

private void showData() {
    
    
        String id = txtId.getText();
        String sql = "select id as 考生号,geography as 地理,chemistry as 化学,IT as 信息技术,History as 历史 ,Biology as 生物,mathematics as 数学,general_technique as 通用技术,physics as 物理,english as 英语,chinese as 语文,politics as 政治  from information_of_grade where id = '"+id+"'";
        DBUtil db = new DBUtil();
        try {
    
    
            db.getConnection();
            ResultSet rs = db.executeQuery(sql, null);
            ResultSetMetaData rsmd = rs.getMetaData();
            int colCount = rsmd.getColumnCount();
            Vector<String> title = new Vector<String>();  //存放标题
            for(int i = 1;i<=colCount;i++) {
    
    
                title.add(rsmd.getColumnLabel(i));
            }
            Vector<Vector<String>> data = new Vector<Vector<String>>();    //存放表格数据
            int rowCount = 0;
            while(rs.next()) {
    
    
                rowCount++;
                Vector<String> rowdata = new Vector<String>();         //存放行数据
                for(int i = 1;i<=colCount;i++) {
    
    
                    rowdata.add(rs.getString(i));
                }
                data.add(rowdata);
            }
            if(rowCount == 0) {
    
    
                model.setDataVector(null, title);
            } else {
    
    
                model.setDataVector(data,title);
            }
        } catch(Exception ee) {
    
    
            System.out.println(ee.toString());
            JOptionPane.showMessageDialog(this, "系统出现异常错误。请检查数据库。系统即将推出!!!","错误",0);
        } finally {
    
    
            db.closeAll();
        }
        JOptionPane.showMessageDialog(null, "查询到该考生信息");
    }

考生查询成绩效果如下:
在这里插入图片描述
考生成绩导出部分代码如下:

public void saveFile() {
    
    
        JFileChooser fc = new JFileChooser();
        int rVal = fc.showSaveDialog(this);
        if(rVal == JFileChooser.APPROVE_OPTION) {
    
    
            String fileName = fc.getSelectedFile().getName();
            String path = fc.getCurrentDirectory().toString();
            try {
    
    
                TableModel model = table.getModel(); 
                FileWriter fw = new FileWriter(path + "/" + fileName);
                for(int i=0; i < model.getColumnCount(); i++) {
    
     
                    fw.write(model.getColumnName(i) + "\t"); 
                } 
                fw.write("\n"); 
                for(int i=0; i< model.getRowCount(); i++) {
    
     
                    for(int j=0; j < model.getColumnCount(); j++) {
    
     
                        fw.write(model.getValueAt(i,j).toString()+"\t"); 
                    } 
                    fw.write("\n");
                } 
                fw.close();
            } catch(Exception e) {
    
    
                e.printStackTrace();
            }
            JOptionPane.showMessageDialog(null, "导出成功");
        }
    }

考生成绩导出效果如下:
在这里插入图片描述
考生修改密码部分代码如下:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               String code = new String(jpCode.getPassword());
               String code1 = new String(jpCode1.getPassword());
               DBUtil db = new DBUtil();
               String sql = "update information_of_students set pwd = '"+code+"' where id = '"+id+"'";
               if(code.equals(code1)){
    
    
                   try {
    
    
                       db.getConnection();
                       db.executeUpdate(sql,null);
                   } catch(Exception ee) {
    
    
                       System.out.println(ee.toString());
                   } finally {
    
    
                       db.closeAll();
                   }
                   JOptionPane.showMessageDialog(null, "修改成功");
               }
               else{
    
    
                   JOptionPane.showMessageDialog(null, "两次密码不一样!");
               }
           }
    }

考生修改密码效果如下:
在这里插入图片描述
管理员主面板部分代码如下:

public MainFrame_Of_Administration() {
    
    
        super("Administration");
        ImageIcon qstIcon = new ImageIcon("images\\1.png");
        this.setIconImage(qstIcon.getImage());
        p = new JPanel();
        setBak();
        clipboard=getToolkit().getSystemClipboard();
        Container c = getContentPane();
        p.setOpaque(false);
        c.add(p);
        p.setLayout(null);

        jbInsert = new JButton("添加考生信息");
        jbDelete = new JButton("删除考生信息");
        jbUpdate = new JButton("修改考生信息");
        jbAdministration = new JButton("返回登录界面");
        jbResetCode = new JButton("重置考生密码");

        jbAdministration.addActionListener(new loginframe_of_administration());
        jbDelete.addActionListener(new listener_of_delete());
        jbInsert.addActionListener(new listener_of_insert());
        jbUpdate.addActionListener(new listener_of_update());
        jbResetCode.addActionListener(new listener_of_reset());

        jbInsert.setBounds(0,20,120,25);
        jbDelete.setBounds(0,55,120,25);
        jbUpdate.setBounds(0,90,120,25);
        jbAdministration.setBounds(0,125,120,25);
        jbResetCode.setBounds(0,165,120,25);

        p.add(jbInsert);
        p.add(jbDelete);
        p.add(jbUpdate);
        p.add(jbAdministration);
        p.add(jbResetCode);
        this.add(p);
        this.setLocation(200,100);
        this.setSize(533,300);
        this.setResizable(false);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

管理员主面板效果如下:
在这里插入图片描述
添加考生信息部分代码如下:

public class listener_of_insert implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               DBUtil db = new DBUtil();
               String preparedsql = "insert into information_of_grade(id,geography,chemistry,IT,history,biology,mathematics,general_technique,physics,english,chinese,politics)"+"values(?,?,?,?,?,?,?,?,?,?,?,?)";

               try {
    
    
                   db.getConnection();
                   Object param[] = {
    
    jtId.getText(),jtGeo.getText(),jtChe.getText(),jtIT.getText(),jtHis.getText(),jtBio.getText(),jtMath.getText(),jtGen.getText(),jtPhy.getText(),jtEng.getText(),jtChi.getText(),jtPol.getText()};
                   db.executeUpdate(preparedsql, param);
               } catch(Exception ee) {
    
    
                   System.out.println(ee.toString());
               } finally {
    
    
                   db.closeAll();
               }
               JOptionPane.showMessageDialog(null, "成功添加考生信息");
        }
    }

添加考生信息效果如下:
在这里插入图片描述
删除考生信息部分代码如下:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               DBUtil db = new DBUtil();
               String sql = "delete from information_of_grade where id = '"+id+"'";

               try {
    
    
                   db.getConnection();
                   db.executeUpdate(sql,null);
               } catch(Exception ee) {
    
    
                   System.out.println(ee.toString());
               } finally {
    
    
                   db.closeAll();
               }
               JOptionPane.showMessageDialog(null, "成功删除考生信息");
        }
    }

删除考生信息效果如下:
在这里插入图片描述
修改考生信息部分代码如下:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               String code = new String(jpCode.getPassword());
               String code1 = new String(jpCode1.getPassword());
               DBUtil db = new DBUtil();
               String sql = "update information_of_students set pwd = '"+code+"' where id = '"+id+"'";
               if(code.equals(code1)){
    
    
                   try {
    
    
                       db.getConnection();
                       db.executeUpdate(sql,null);
                   } catch(Exception ee) {
    
    
                       System.out.println(ee.toString());
                   } finally {
    
    
                       db.closeAll();
                   }
                   JOptionPane.showMessageDialog(null, "修改成功");
               }
               else{
    
    
                   JOptionPane.showMessageDialog(null, "两次密码不一样!");
               }
           }
    }

修改考生信息效果如下:
在这里插入图片描述
重置考生密码部分代码如下:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               DBUtil db = new DBUtil();
               String sql = "update information_of_students set pwd = '000000' where id = '"+id+"'";
               try {
    
    
                   db.getConnection();
                   db.executeUpdate(sql,null);
               } catch(Exception ee) {
    
    
                   System.out.println(ee.toString());
               } finally {
    
    
                   db.closeAll();
                 }
                 JOptionPane.showMessageDialog(null, "重置成功");
           }
    }

重置考生密码效果如下:
在这里插入图片描述

四、完整源码下载

学生会考成绩管理系统源码下载:

  • 关注我的原创微信公众号:『小鸿星空科技』,回复『学生会考成绩管理系统』获取完整项目
    在这里插入图片描述

五、作者Info

作者:小鸿的摸鱼日常,Goal:让编程更有趣!

原创微信公众号:『小鸿星空科技』,专注于算法、网络爬虫,网站开发,游戏开发,数据分析、自然语言处理,AI等,期待你的关注,让我们一起成长、一起Coding!

版权说明:本文禁止抄袭、转载 ,侵权必究!

猜你喜欢

转载自blog.csdn.net/qq_44000141/article/details/122275351