编程语言
首页 > 编程语言> > java课程设计—学生成绩管理系统

java课程设计—学生成绩管理系统

作者:互联网

团队名称:hxgxy

本人负责分工:

1.实现教师窗口

2.实现学生窗口

3.实现教师菜单

4.实现修改学生信息菜单

5.实现展示学生信息菜单。

1.实现教师窗口

package view;

import javax.swing.JOptionPane;


/**
 * @author tiome 2021年6月19日
 *
 */
public class TeacherFrame extends javax.swing.JFrame {

    /**
     * 创建教师登录窗体
     */
    public TeacherFrame() {
        initComponents();
    }

    /**
     *初始化窗口
     */
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();//创建窗口面板,便于更改颜色
        jLabel1 = new javax.swing.JLabel();//创建“账号”标签
        jLabel2 = new javax.swing.JLabel();//创建“密码”标签
        jButton1 = new javax.swing.JButton();//创建“登录”按钮
        jButton2 = new javax.swing.JButton();//创建“退出”按钮
        nameTextField1 = new javax.swing.JFormattedTextField();//创建账号输入文本框
        passwordField1 = new javax.swing.JPasswordField();//创建密码输入文本框

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//设置窗口关闭及停止程序
        
        //设置窗体背景颜色,标题。组件的名称及颜色
        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setToolTipText("教师登录");

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("账号");

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("密码");

        jButton1.setBackground(new java.awt.Color(255, 255, 204));
        jButton1.setText("登录");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);//设置“登录”的动作监听器及发生时所调用的方法
            }
        });

        jButton2.setBackground(new java.awt.Color(255, 255, 204));
        jButton2.setText("退出");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);//设置“退出”的动作监听器及发生时所调用的方法
            }
        });

        nameTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameTextField1ActionPerformed(evt);//设置“账号文本框”的动作监听器及发生时所调用的方法
            }
        });

        passwordField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passwordField1ActionPerformed(evt);//设置“密码文本框”的动作监听器及发生时所调用的方法
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);//设置分组布局
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(//设置水平分组,设置组之间间距,添加组员“账号”,“密码”,“账号文本框”,“密码文本框”,“登录”,“退出”等操作
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(95, 95, 95)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(55, 55, 55)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(42, 42, 42)
                        .addComponent(jButton2))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(nameTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(passwordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        
        jPanel1Layout.setVerticalGroup(//设置竖直分组,设置组之间间距,添加组员“账号”,“密码”,“账号文本框”,“密码文本框”,“登录”,“退出”等操作
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(82, 82, 82)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nameTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passwordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(84, 84, 84)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(121, Short.MAX_VALUE))
        );
        //获取内容面板,添加水平竖直分组组件
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();//调整此窗口的大小,以适合其子组件的首选大小和布局
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//获取“账号”,“密码”,与数据库相匹配(动作监听器所执行操作)
         String name=nameTextField1.getText();
         char[]password=passwordField1.getPassword();
         String pwd=new String(password);
         LoginServer server=new LoginServer();
         if(LoginServer.login(name,pwd)){
             JOptionPane.showMessageDialog(this, "登录成功");//若匹配成功则显示“登陆成功”并进入老师菜单,若不成功,则显示“账号或密码输入错误,请重新输入”,不展开老师菜单
             TeacherMenu menu=new TeacherMenu();
             menu.setVisible(true);
             this.setVisible(false);
             this.dispose();
         }
         else
         {
              JOptionPane.showMessageDialog(this, "账户或密码输入错误,请重新输入");
         }
         
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//若点击“退出”,则系统退出(动作监听器所执行操作)
       System.exit(0);
    }

    private void passwordField1ActionPerformed(java.awt.event.ActionEvent evt) {//(动作监听器所执行操作)
       
    }

    private void nameTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//(动作监听器所执行操作)
       
        
    }

    /**
     * Main函数,美化窗口,抛出错误所执行操作
     */
    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(TeacherFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TeacherFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TeacherFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TeacherFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
    

        //展示老师窗口
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TeacherFrame().setVisible(true);
            }
        });
    }

    // 私人变量声明
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JFormattedTextField nameTextField1;
    private javax.swing.JPasswordField passwordField1;

}

 

2.实现学生窗口

 

package view;


import javax.swing.JOptionPane;
import model.User;
/**
 * @author tiome 2021年6月19日
 *
 */
public class StudentFrame extends javax.swing.JFrame {

    /**
     * 创建学生登录窗体
     */
    public StudentFrame() {
        initComponents();
    }

    /**
     * 初始化窗体
     */
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();//创建窗口面板,便于更改颜色
        jButton1 = new javax.swing.JButton();//创建“登录”按钮
        jButton2 = new javax.swing.JButton();//创建“退出”按钮
        jLabel1 = new javax.swing.JLabel();//创建“账号”标签
        jLabel2 = new javax.swing.JLabel();//创建“密码”标签
        TextField = new javax.swing.JFormattedTextField();//创建账号输入文本框
        PasswordField = new javax.swing.JPasswordField();//创建密码输入文本框

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//设置窗口关闭及停止程序

        //设置窗体背景颜色,标题。组件的名称、颜色及各个组件的动作监听器
        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setText("登录");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(255, 255, 255));
        jButton2.setText("退出");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setText("账号");

        jLabel2.setText("密码");

        //设置分组布局
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        
        //设置水平分组,设置组之间间距,添加组员“账号”,“密码”,“账号文本框”,“密码文本框”,“登录”,“退出”等操作
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(203, 203, 203)
                        .addComponent(jButton1)
                        .addGap(61, 61, 61)
                        .addComponent(jButton2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addComponent(PasswordField))))
                .addContainerGap(169, Short.MAX_VALUE))
        );
        //设置竖直分组,设置组之间间距,添加组员“账号”,“密码”,“账号文本框”,“密码文本框”,“登录”,“退出”等操作
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(61, 61, 61)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(107, 107, 107)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(179, Short.MAX_VALUE))
        );
        //获取内容面板,添加水平竖直分组组件
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();//调整此窗口的大小,以适合其子组件的首选大小和布局
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//若点击“退出”,则系统退出(动作监听器所执行操作)
       System.exit(0);
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//获取“账号”,“密码”,与数据库相匹配(动作监听器所执行操作)
       String name=TextField.getText();
         char[]password=PasswordField.getPassword();
         String pwd=new String(password);
         User server=new User();
         if(User.login(name,pwd)){
             JOptionPane.showMessageDialog(this, "登录成功");//若匹配成功则显示“登陆成功”并进入学生个人窗口,若不成功,则显示“账号或密码输入错误,请重新输入”,不展开学生个人窗口
             PersonFrame menu=new PersonFrame();
             menu.setVisible(true);
             this.setVisible(false);
             this.dispose();
         }
         else
         {
             JOptionPane.showMessageDialog(this, "账户或密码输入错误,请重新输入");
         }
    }

    /**
     * Main函数,美化窗口,抛出错误所执行操作
     */
    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(StudentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StudentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StudentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StudentFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        //展示学生窗口
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new StudentFrame().setVisible(true);
            }
        });
    }

    //私人变量声明
    private javax.swing.JPasswordField PasswordField;
    private javax.swing.JFormattedTextField TextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
}

 

3.实现教师菜单

 

package view;

/**
 * @author tiome 2021年6月19日
 *
 */
public class TeacherMenu extends javax.swing.JFrame {

    /**
     * 创建老师菜单窗体
     */
    public TeacherMenu() {
        initComponents();
    }
    //初始化窗口
    
    private void initComponents() {//创建面板,创建“添加学生”,“删除学生”,“查找学生”,“修改学生信息”,“导出学生信息”,“查看学生信息”,“返回”按钮
    	
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//设置窗口关闭及停止程序

        //设置窗体背景颜色。组件的名称、颜色、大小及各个组件的动作监听器
        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        jButton1.setBackground(new java.awt.Color(255, 255, 102));
        jButton1.setText("1.添加学生");
        jButton1.setPreferredSize(new java.awt.Dimension(125, 29));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(255, 255, 102));
        jButton2.setText("2.删除学生");
        jButton2.setPreferredSize(new java.awt.Dimension(125, 29));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(255, 255, 102));
        jButton3.setText("3.查找学生");
        jButton3.setPreferredSize(new java.awt.Dimension(125, 29));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setBackground(new java.awt.Color(255, 255, 102));
        jButton4.setText("4.修改学生信息");
        jButton4.setPreferredSize(new java.awt.Dimension(125, 29));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setBackground(new java.awt.Color(255, 255, 102));
        jButton5.setText("6.查看学生信息");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setBackground(new java.awt.Color(255, 255, 102));
        jButton6.setText("5.导出学生信息");
        jButton6.setPreferredSize(new java.awt.Dimension(125, 29));
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setBackground(new java.awt.Color(255, 255, 255));
        jButton7.setText("返回");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        //设置分组布局
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
      
        //设置水平分组,设置间距,添加组员“添加学生”,“删除学生”,“查找学生”,“修改学生信息”,“导出学生信息”,“查看学生信息”,“返回”等操作
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(223, 223, 223)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(263, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton7)
                .addGap(61, 61, 61))
        );
        
        //设置水平分组,设置间距,添加组员“添加学生”,“删除学生”,“查找学生”,“修改学生信息”,“导出学生信息”,“查看学生信息”,“返回”等操作
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                .addComponent(jButton7)
                .addGap(43, 43, 43))
        );

        
        //获取内容面板,添加水平竖直分组组件及大小间距
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }//调整此窗口的大小,以适合其子组件的首选大小和布局

    
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//“添加学生”动作监听器若捕捉到动作,则会打开添加学生窗口,否则则不会
       AddFrame  frame=new AddFrame();
       frame.setVisible(true);
       this.setVisible(false);
       this.dispose();//释放所有本机屏幕资源,添加学生窗口不显示
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//“删除学生”动作监听器若捕捉到动作,则会打开删除学生窗口,否则则不会
       DeleteFrame  frame=new DeleteFrame();
       frame.setVisible(true);
       this.setVisible(false);
       this.dispose();
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//“修改学生信息”动作监听器若捕捉到动作,则会打开修改学生信息,否则则不会
       UpdataFrame frame=new UpdataFrame();
       frame.setVisible(true);
       this.setVisible(false);
       this.dispose();        
    }

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//“查看学生信息”动作监听器若捕捉到动作,则会打开展示学生信息窗口,否则则不会
       ShowFrame frame=new ShowFrame();
       frame.setVisible(true);
       this.setVisible(false);
       this.dispose();  
    }

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//“导出学生信息”动作监听器若捕捉到动作,则会导出学生信息,否则则不会
       //有待实现
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//“查找学生”动作监听器若捕捉到动作,则会打开查找学生窗口,否则则不会
      FindFrame frame=new FindFrame();
      frame.setVisible(true);
      this.setVisible(false);
      this.dispose();
    }

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//“返回”动作监听器若捕捉到动作,则会关闭当前窗口并且打开登录菜单窗口,否则则不会
       Login menu=new Login();
       menu.setVisible(true);
       this.setVisible(false);
       this.dispose();
    }

    /**
     * Main函数,美化窗口,抛出错误所执行操作
     */
    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(TeacherMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TeacherMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TeacherMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TeacherMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        

        //展示老师窗口
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TeacherMenu().setVisible(true);
            }
        });
    }

    //私人变量声明
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JPanel jPanel1;
    
}

 

4.实现修改学生信息菜单

 

package view;

import model.Student;
import model.Course;
import dao.StudentSystemDao;
import dao.StudentSystemDaoJDBCImpl;
import javax.swing.JOptionPane;


/**
 * @author tiome 2021年6月19日
 *
 */
public class UpdataFrame extends javax.swing.JFrame {

    /**
     * 创建修改学生信息窗口
     */
    public UpdataFrame() {
        initComponents();
    }
    //初始化窗口
   

    private void initComponents() {

        classroom = new javax.swing.JPanel();//设置窗体面板
        jLabel1 = new javax.swing.JLabel();//设置"请输入要修改学生的id"标签
        id = new javax.swing.JFormattedTextField();//设置“id”输入文本框
        jButton1 = new javax.swing.JButton();//设置“确定”按钮
        room = new javax.swing.JRadioButton();//设置“班级”单选按钮
        ageButton = new javax.swing.JRadioButton();//设置“年龄”单选按钮
        nameButton = new javax.swing.JRadioButton();//设置“姓名”单选按钮
        javaButton = new javax.swing.JRadioButton();//设置“java成绩”单选按钮
        mathButton = new javax.swing.JRadioButton();//设置“数学成绩”单选按钮
        sportButton = new javax.swing.JRadioButton();//设置“体育成绩”单选按钮
        stuClass = new javax.swing.JFormattedTextField();//设置“班级输入文本框”
        nameText = new javax.swing.JFormattedTextField();//设置“姓名输入文本框”
        mathText = new javax.swing.JFormattedTextField();//设置“数学成绩输入文本框”
        sportText = new javax.swing.JFormattedTextField();//设置“体育成绩输入文本框”
        ageText = new javax.swing.JFormattedTextField();//设置“年龄输入文本框”
        javaText = new javax.swing.JFormattedTextField();//设置“java成绩输入文本框”
        jLabel2 = new javax.swing.JLabel();//设置"请选择要修改的对象并填入修改信息"标签
        jButton2 = new javax.swing.JButton();//设置“返回”按钮

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//设置窗口关闭及停止程序

        //设置窗体背景颜色,标题。组件的名称、颜色及各个组件的动作监听器
        classroom.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setText("请输入要修改学生的id");

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setText("确定");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        room.setText("班级");

        ageButton.setText("年龄");

        nameButton.setText("姓名");

        javaButton.setText("Java成绩");

        mathButton.setText("数学成绩");
        mathButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mathButtonActionPerformed(evt);
            }
        });

        sportButton.setText("体育成绩");

        jLabel2.setText("请选择要修改的对象并填入修改信息");

        jButton2.setBackground(new java.awt.Color(255, 255, 255));
        jButton2.setText("返回");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        //设置分组布局
        javax.swing.GroupLayout classroomLayout = new javax.swing.GroupLayout(classroom);
        classroom.setLayout(classroomLayout);
        //设置水平分组,添加组件,设置间距
        classroomLayout.setHorizontalGroup(
            classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(classroomLayout.createSequentialGroup()
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(classroomLayout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(classroomLayout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addComponent(jLabel1)
                                .addGap(32, 32, 32)
                                .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(classroomLayout.createSequentialGroup()
                                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(mathButton)
                                    .addComponent(nameButton)
                                    .addComponent(room))
                                .addGap(18, 18, 18)
                                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(stuClass, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                    .addComponent(nameText)
                                    .addComponent(mathText))
                                .addGap(31, 31, 31)
                                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(classroomLayout.createSequentialGroup()
                                        .addComponent(sportButton)
                                        .addGap(18, 18, 18)
                                        .addComponent(sportText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(classroomLayout.createSequentialGroup()
                                        .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(javaButton)
                                            .addComponent(ageButton))
                                        .addGap(18, 18, 18)
                                        .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(ageText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(javaText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                    .addGroup(classroomLayout.createSequentialGroup()
                        .addGap(138, 138, 138)
                        .addComponent(jLabel2)))
                .addContainerGap(133, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, classroomLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(27, 27, 27)
                .addComponent(jButton2)
                .addGap(67, 67, 67))
        );
        //设置竖直分组,添加组件,设置间距
        classroomLayout.setVerticalGroup(
            classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(classroomLayout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(jLabel2)
                .addGap(31, 31, 31)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(room)
                    .addComponent(stuClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ageButton)
                    .addComponent(ageText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameButton)
                    .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(javaButton)
                    .addComponent(javaText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(53, 53, 53)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mathButton)
                    .addComponent(mathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sportButton)
                    .addComponent(sportText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(50, 50, 50))
        );

        //获取内容面板,添加水平竖直分组组件
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(classroom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(classroom, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();//调整此窗口的大小,以适合其子组件的首选大小和布局
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//设置“确定”按钮动作监听器所执行的动作,若“确定”被点击,则会将“班级”,“年龄”,“姓名”,“java成绩”,“数学成绩”,“体育成绩”中输入的根据学生id替换数据库中的数据
       int stuId=Integer.valueOf(id.getText());//
       Student stu=new Student();
       StudentSystemDao system=new StudentSystemDaoJDBCImpl();
       stu=system.findStudentById(stuId);
       if(room.isSelected())
       {
           String clazz=stuClass.getText();
           stu.setClazz(clazz);  
       }
       else if(ageButton.isSelected())
       {
           int stuAge=Integer.valueOf(ageText.getText());
           stu.setAge(stuAge);
       }
       else if(nameButton.isSelected())
       {
           String stuName=nameText.getText();
           stu.setName(stuName);
          
       }
       else if(javaButton.isSelected())
       {
           Double stuJava=Double.valueOf(javaText.getText());
           Course java=new Course("java",stuJava);
           stu.getCourseList().get(0).setScore(stuJava);
           
       }
       else if(mathButton.isSelected())
       {
            Double stuMath=Double.valueOf(mathText.getText());
           Course math=new Course("math",stuMath);
           stu.getCourseList().get(1).setScore(stuMath);
          
       }
       else if(sportButton.isSelected())
       {
            Double stuSport=Double.valueOf(sportText.getText());
           Course sport=new Course("sport",stuSport);
           stu.getCourseList().get(2).setScore(stuSport);
       }
       if(system.update(stu))//若修改成功明则显示“修改成功”,否则显示“修改失败”
       {
            JOptionPane.showMessageDialog(this, "修改成功");
       }
       else
       {
            JOptionPane.showMessageDialog(this, "修改失败");
       }
       
    }

    private void mathButtonActionPerformed(java.awt.event.ActionEvent evt) {//“数学成绩”按钮动作监听器方法
        
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//若点击“返回”按钮,则会关闭当前窗口并显示老师菜单窗口
        TeacherMenu menu=new TeacherMenu();
        menu.setVisible(true);
        this.setVisible(false);
        this.dispose();
    }

    /**
     *Main函数,美化窗口,抛出错误所执行操作
     */
    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(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        

        //展示修改学生信息窗口
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UpdataFrame().setVisible(true);
            }
        });
    }

    // 私人变量生命
    private javax.swing.JRadioButton ageButton;
    private javax.swing.JFormattedTextField ageText;
    private javax.swing.JPanel classroom;
    private javax.swing.JFormattedTextField id;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton javaButton;
    private javax.swing.JFormattedTextField javaText;
    private javax.swing.JRadioButton mathButton;
    private javax.swing.JFormattedTextField mathText;
    private javax.swing.JRadioButton nameButton;
    private javax.swing.JFormattedTextField nameText;
    private javax.swing.JRadioButton room;
    private javax.swing.JRadioButton sportButton;
    private javax.swing.JFormattedTextField sportText;
    private javax.swing.JFormattedTextField stuClass;
    
}

 

5.实现展示学生信息菜单。

 

package view;

import dao.StudentSystemDao;
import dao.StudentSystemDaoJDBCImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import model.Student;


/**
 * @author tiome 2021年6月15日
 *
 */
public class ShowFrame extends javax.swing.JFrame {

    /**
     *创建展示学生信息窗口
     */
    public ShowFrame() {
         
        initComponents();
    }

    /**
     *初始化窗口
     */

    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        text = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//设置窗口关闭及停止程序

        //设置背景颜色
        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        //设置一个表格模型,用于展示学生信息
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            //定义类型type展示的字符串数组
            new String [] {
                "stuId", "name", "isMale", "age", "clazz", "java", "math", "sport"
            }
        ) {
            Class[] types = new Class [] {//定义类型type
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
            };
            
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTable1.setName("1"); //创建表格
        //设置面板及背景色
        jScrollPane1.setViewportView(jTable1);
        text.setBackground(new java.awt.Color(255, 255, 255));
        //设置“查看”及其动作监听器
        text.setText("查看");
        text.addActionListener(new java.awt.event.ActionListener() {
        	
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textActionPerformed(evt);
            }
        });
        
        //设置“返回”及其动作监听器
        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setText("返回");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
        	
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        //设置分组布局
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        //设置水平分组
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 790, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(269, 269, 269)
                .addComponent(text)
                .addGap(51, 51, 51)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        //设置竖直分组
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text)
                    .addComponent(jButton1))
                .addGap(97, 97, 97))
        );
      
        //获取内容面板,添加水平竖直分组组件及间距
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 1, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();//调整此窗口的大小,以适合其子组件的首选大小和布局
    }

    private void textActionPerformed(java.awt.event.ActionEvent evt) {//若点击“查看”,则会构造一个表格模型并展示数据库中全部学生信息(动作监听器动作)
      List<Student> student = new ArrayList<Student>();
       StudentSystemDao system=new StudentSystemDaoJDBCImpl();
       student=system.getAllStudents();
       DefaultTableModel dtm=(DefaultTableModel)jTable1.getModel();//默认构造器,0行0列
       Vector vector=new Vector();
       for(Student e:student)
       {
           vector.add(e);
           dtm.addRow(vector);
       }
        
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//若点击“返回”按钮,则会关闭当前窗口,打开老师菜单窗口
        TeacherMenu menu=new TeacherMenu();
        menu.setVisible(true);
        this.setVisible(false);
        this.dispose();
    }

    /**
     *Main函数,美化窗口,抛出错误所执行操作
     */
    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(ShowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ShowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ShowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ShowFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        //展示“展示学生信息”窗口
        java.awt.EventQueue.invokeLater(new Runnable() {
        	@Override
            public void run() {
            	
                new ShowFrame().setVisible(true);
            }
        });
    }

    //私人变量声明
    private javax.swing.JButton text;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
}

 

标签:课程设计,java,管理系统,GroupLayout,swing,new,javax,SIZE
来源: https://blog.csdn.net/qq_58154909/article/details/118085286