基于Java+MySQL实现(GUI )信息管理系统

发布于:2025-08-02 ⋅ 阅读:(17) ⋅ 点赞:(0)

信息管理系统

1 概述

随着社会的发展,科技的不断进步,使得高校的信息化管理出现了新方向。一个现代化的高校想要更好的生存和发展,必须跟上信息化的步伐,对学生的信息管理当下已是一个十分重要的事情。

本系统后台数据库采用 My SQL 数据库,该数据库在安全性、准确性和运行速度方面有绝对的优势,并且处理量大,效率高;前台采用 NetBeans 作为主要的开发工具,可与 My SQL 数据库实现无缝连接。该系统针对学校学生信息的特点以及管理中实际需要而设计,能够有效地实现学生信息管理的信息化,减轻管理人员的工作负担,高效率、规范化地管理大量的学生信息,并避免人为操作的错误和不规范行为

2 总体设计

系统功能流程图

概述:通过 NetBeans 来构建该信息管理系统的基本框架,然后通过与 MySQL 数据库的连接来实现信息的增、删、改、查等操作,并实现程序的有效运行。

3 详细设计

3.1、登陆界面

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    new UserFindPasswordFrame().setVisible(true);
    this.setVisible(false);
}    //登陆                                     
private void loginBtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
    //登录验证功能
    UserDao userDao=new UserDaoImpl();
    userDao.login(userName.getText().trim(), password.getText().trim());
    if (userName.getText().equals(password.getText())) 
    {    new JSelect().setVisible(true);//新建了一个窗体,并显示
     this.setVisible(false);
    } else {
        JOptionPane.showMessageDialog(null, "用户名不存在或密码错误,请找回密码!");
    }
}                                        
//注册按钮功能
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    new UserAddFrame().setVisible(true);
    this.setVisible(false);}                                        
public static void main(String args[]) {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {  if ("Nimbus".equals(info.getName())) {
            javax.swing.UIManager.setLookAndFeel(info.getClassName());
            break;
        }}
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new Login().setVisible(true);
        }
    });}

运行结果如下:

3.2 注册账号

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    System.out.println("注册按钮被点击。");
    String UserName=tf_userName.getText().trim();
    String UserPassword=tf_password.getText().trim();
    String UserPassword2=tf_password2.getText().trim();
    if(UserPassword.equals(UserPassword2)){
        System.out.println("把用户名,密码插入数据库中。");
        String driverName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useSSL=false";
        String userName = "root";
        String password = "123456";
        try {
            Class.forName(driverName);
            Connection conn = DriverManager.getConnection(url, userName, password);
            String sql="insert into user(Name,Password) value (?,?)";
            PreparedStatement pstat = conn.prepareStatement(sql);
            pstat.setString(1, UserName);
            pstat.setString(2, UserPassword);
            if(pstat.executeUpdate()==1){
                System.out.println("插入了一条记录");
                System.out.println("用户名:"+UserName);
                System.out.println("密码:"+UserPassword);
                JOptionPane.showMessageDialog(null, "插入了一条记录"+"用户名:"+UserName+"密码:"+UserPassword);
            }else{
                System.out.println("插入失败");
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(UserAddFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(UserAddFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }else{
        System.out.println("两次输入的密码不一致.");
    }
}

运行结果如下:

3.3 找回密码

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{     System.out.println("找回密码按钮被点击");
 String tf_UserNameStr=tf_userName.getText().trim();
 try {    Connection conn = JDBCUtil.connectiontt();
      String sql="select * from user where Name=?";
      PreparedStatement pstat = conn.prepareStatement(sql);
      pstat.setString(1, tf_UserNameStr);
      ResultSet rs=pstat.executeQuery();
      if(rs.next()){
          System.out.println("找到了"+tf_UserNameStr+"用户的密码:"+rs.getString("Password"));
          lb_userPassword.setText(rs.getString("Password"));
          JOptionPane.showMessageDialog(null, "找到了"+tf_UserNameStr+"用户的密码:"+rs.getString("Password"));
      }else{
          System.out.println("找不到用户信息");
          JOptionPane.showMessageDialog(null,"找不到用户信息");
      }
     } catch (Exception ex) {
     Logger.getLogger(UserAddFrame.class.getName()).log(Level.SEVERE, null, ex);
 }}                                        
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    this.setVisible(false);
    new Login().setVisible(true);
}

运行结果如下:

3.4、学生信息主界面

private void jMenuItem2MousePressed(java.awt.event.MouseEvent evt) {                                        
    System.out.println("更新表格数据jMenuItem2MousePressed");
    String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
    Object[][] data = {
        {"Kathy", "Smith",
         "Snowboarding", new Integer(5), new Boolean(false)},
        {"John", "Doe",
         "Rowing", new Integer(3), new Boolean(true)},
        {"Sue", "Black",
         "Knitting", new Integer(2), new Boolean(false)},
        {"Jane", "White",
         "Speed reading", new Integer(20), new Boolean(true)},
        {"Joe", "Brown",
         "Pool", new Integer(10), new Boolean(false)}
    };
    Vector columnNamesStudent = new Vector();
    columnNamesStudent.add("学号");
    columnNamesStudent.add("姓名");
    columnNamesStudent.add("性别");
    columnNamesStudent.add("出生日期");
    columnNamesStudent.add("数学成绩");
    columnNamesStudent.add("Java成绩");
    columnNamesStudent.add("体育成绩");
    columnNamesStudent.add("总分");
    Vector data2 = new Vector();
    if (ll == null) {
        ll = new StudentDaoJDBCImpl().diplayAllStudent();}
    for (int i = 0; i < ll.size(); i++) {
        Vector dataRow = new Vector();
        dataRow.add(ll.get(i).getId());
        dataRow.add(ll.get(i).getName());
        dataRow.add(ll.get(i).getGender());
        dataRow.add(ll.get(i).getBirthday());
        dataRow.add(Double.toString(ll.get(i).getScoreList().get(0).getScore()));
        dataRow.add(Double.toString(ll.get(i).getScoreList().get(1).getScore()));
        dataRow.add(Double.toString(ll.get(i).getScoreList().get(2).getScore()));
        dataRow.add(Double.toString(ll.get(i).getTotalpoint()));
        data2.add(dataRow); }
    JTable jTable3 = new JTable(data2, columnNamesStudent);
    jScrollPane2.setViewportView(jTable3);
    jTable3.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {//仅当鼠标单击时响应
            //得到选中的行列的索引值
            int r = jTable3.getSelectedRow();
            int c = jTable3.getSelectedColumn();
            //得到选中的单元格的值,表格中都是字符串
            Object value = jTable3.getValueAt(r, c);
            JPanelScore.main(ll.get(r));
            String info = r + "行" + c + "列值 : " + ll.get(r);
            javax.swing.JOptionPane.showMessageDialog(null, info);
        }});}                                       
private void jMenuItem4MouseClicked(java.awt.event.MouseEvent evt) {                                        
    System.out.println("柱状图数据分析 ");
}                                       
private void jMenuItem4MousePressed(java.awt.event.MouseEvent evt) {                                        
    System.out.println("柱状图数据分析 jMenuItem4MousePressed");
    new NewJFrame_About().setVisible(true);
}                                       
public static void main(String args[]) {
        try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {           if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }}
        } catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }    
        StudentDaoJDBCImpl students = new StudentDaoJDBCImpl();
        ll = students.diplayAllStudent();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            } }); }

3.5、客户信息界面

private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {                                        
    System.out.println("客户更新事件被触发");
    CustomerInfoDao infoDao=new CustomerInfoDaoImpl();
    Vector columnNamesCustomer=new Vector();
    columnNamesCustomer.add("CID");
    columnNamesCustomer.add("客户名称");
    columnNamesCustomer.add("客户电话");
    columnNamesCustomer.add("客户地址");
    columnNamesCustomer.add("备注");
    Vector data2=new Vector();
    if(list==null){
        list=infoDao.displayAllCustomerInfo();}
    for(int i=0;i<list.size();i++){
        Vector dataRow=new Vector();
        dataRow.add(list.get(i).getCID());
        dataRow.add(list.get(i).getCustomerName());
        dataRow.add(list.get(i).getCustomerTel());
        dataRow.add(list.get(i).getCustomerAddress());
        dataRow.add(list.get(i).getCustomerDesc());
        data2.add(dataRow);}
    JTable table2=new JTable(data2,columnNamesCustomer);
    table2.addMouseListener(new MouseAdapter(){
        public void mouseClicked(MouseEvent e) 
        {      int r=table2.getSelectedRow();
         int c=table2.getSelectedColumn();
         System.out.println("r="+r+" c="+c);
         new CustomerEditFrame(list.get(r)).setVisible(true);
        }});
    this.jScrollPane1.setViewportView(table2);}                                       
private void jMenuItem2MousePressed(java.awt.event.MouseEvent evt) {                                        
    this.setVisible(false);
    new JSelect().setVisible(true);}                                       
public static void main(String args[]) {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;} }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(CustomerInfosFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(CustomerInfosFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(CustomerInfosFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(CustomerInfosFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new CustomerInfosFrame().setVisible(true);
        }});}

运行结果如下:

3.6 对客户信息进行修改

public CustomerEditFrame() {
    initComponents();
    initMyself();}
public CustomerEditFrame(CustomerInfo c) {
this.customer=c;
initComponents();
initMyself();}
private void initMyself(){
    if(customer!=null){
        this.tf_cid.setText(Integer.toString(customer.getCID()));
        this.tf_name.setText(customer.getCustomerName());
        this.tf_tele.setText(customer.getCustomerTel());
        this.tf_address.setText(customer.getCustomerAddress());
        this.tf_desc.setText(customer.getCustomerDesc());
    }else{
        JOptionPane.showMessageDialog(null, "没有传递进来客户信息");
    }}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    System.out.println("保存修改");
    CustomerInfoDao dao=new CustomerInfoDaoImpl();
    customer.setCustomerName(this.tf_name.getText());
    customer.setCustomerTel(this.tf_tele.getText());
    customer.setCustomerAddress(this.tf_address.getText());
    customer.setCustomerDesc(this.tf_desc.getText());
    int count=dao.updateCustomerInfo(customer);
    if(count>0){
        System.out.println("更新成功");
    }else{
        System.out.println("更新失败");
    }
}

运行结果如下:

3.7 新建客户

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Customer c=new Customer();
    c.setCustomerName(textField1.getText().trim());
    c.setCustomerTel(textField2.getText().trim());
    c.setCustomerAddress(textField3.getText().trim());
    c.setCustomerDesc(textField4.getText().trim());
    Connection conn = null;


    PreparedStatement pstat = null;
    String sql = ("insert into customerinfo(CustomerName,CustomerTel,CustomerAddress,CustomerDesc) values(?,?,?,?)");
    int result = -1;
    try {
        conn = JDBCUtil.getConnection();
        pstat = conn.prepareStatement(sql);
        pstat.setString(1, c.getCustomerName());
        pstat.setString(2, c.getCustomerTel());			
        pstat.setString(3, c.getCustomerAddress());
        pstat.setString(4, c.getCustomerDesc());
        result = pstat.executeUpdate();
        if(result==1){
            JOptionPane.showMessageDialog(null, "插入成功");
        }else{
            JOptionPane.showMessageDialog(null, "插入失败");
        }
    } catch (SQLException sqle) {
        sqle.printStackTrace();}
}                                        
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    this.setVisible(false);
}

4 运行结果与调试

4.1 登陆

4.2 选择窗口

4.3 学生成绩

4.4 查找学生

4.5 删除学生信息

4.6 新建学生信息

4.8 数据库

结束语

通过这次 Java 实训,让我加深了对 Java 课程的了解,而不只是单单的在课本中学到的那些理论,平时乏味的课程,通过自己动手亲自编写,变的生动有趣,而在自己动手的过程中,出现的问题很多,比理论要难的多,当一个程序写完以后,经常会有很多错误而没法解决。不过,通过几天的实训,逐渐积攒了一些经验,有些错误可以很快就看出来。

这次实训我收获了很多,让我对 Java 有了更深的认识,平时在课堂上学到的东西可以自己动手编写,将其转化成一些实用的技能。如果是一个程序写完一处错误也没有,会有种成就感,于是兴趣就来了,兴趣来了,自然学的东西也就多了,能把理论变成实际的技能,让我对 Java 有了浓厚的兴趣和更深层的认识。一方面学习到了许多以前没学过的专业知识与知识的应用,另一方面还提高了自己动手做项目的能力。

有时候自己的设计思路还是不够成熟,考虑的不够周全,导致后续工作无法运行,还需要认真修改,在做一些构造的时候总是不够清晰,使得在做的时候感觉到无法进行下去了。有时候做事情要换个角度思考,自己坚持的思路不一定是最好的,在无法进行下去的时候我们转换一些思考角度也许会收到意想不到的效果。其次,它锻炼了我们做项目的能力,提高了独立思考问题、自己动手操作的能力,在做的过程中,复习了以前学习过的知识,并掌握了一些应用知识的技巧等,通过这次合作也使我们更加有团队精神。

参考资料

[1] 王珊 萨师煊 .数据库系统概论 [M].高等教育出版社,2006.5

[2]毕广吉.Java 程序设计实例教程[M]. 北京:冶金工业出版社,2007

[3]王保罗.Java 面向对象程序设计[M]. 北京:清华大学出版社,2003

[4].高林,周海燕.Jsp 网上书店系统与案例分析[M]. 北京:人民邮电出版社,2004

[5].刘腾红,孙细明.信息系统分析与设计[M]. 北京:科学出版社,2003

[6].林邦杰,彻底研究 java.北京:电子工业出版社,2002


网站公告

今日签到

点亮在社区的每一天
去签到