第六天实训:学生信息管理系统

接着第5天的实训
14)按姓名查询学生窗口FindStudentsByName
package net.zzm.student.gui;
import net.zzm.student.bean.Student;
import net.zzm.student.service.StudentService;
import net.zzm.student.service.impl.StudentServicelmpl;

import javax.swing.;
import javax.swing.border.TitledBorder;
import java.awt.
;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.util.Vector;
import java.util.List;

public class FindStudentsByNameFrame extends JFrame {
/**
* 姓名标签
/
private JLabel lblInputName;
/
*
* 姓名文本框
*/
private JTextField txtName;

/**
 * 面板
 */
private JPanel panel;
private JPanel pnlSouth;
private JPanel pnlCenter;
private JPanel pnlNorth;

/**
 * 按钮
 */
private JButton btnQuery;
private JButton btnBrowseAll;
private JButton btnPrint;
private JButton btnExit;

/**
 * 记录行集
 */
private Vector rows;
/**
 * 表格列标题
 */
private Vector colHead;
/**
 * 表格
 */
private JTable table;
/**
 * 滚动面板
 */
private JScrollPane scroller;

/**
 * 当前记录行号
 */
private int currentRow;
/**
 * 学生列表
 */
private List students;
/**
 * 创建学生服务对象
 */
private StudentService studentService;

/**
 * 构造方法
 *
 * @param title
 */
public FindStudentsByNameFrame(String title) {
    super(title);
    intiGUI();
}

/**
 * 初始化用户界面
 */
private void intiGUI() {
    // 创建对象
    panel = (JPanel) getContentPane();
    pnlNorth = new JPanel();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();

    rows = new Vector();
    colHead = new Vector();

    lblInputName = new JLabel("输入姓名:");
    txtName = new JTextField(10);
    txtName.setHorizontalAlignment(JTextField.CENTER);
    btnQuery = new JButton("查询[Q]");
    btnQuery.setMnemonic(KeyEvent.VK_Q);
    btnBrowseAll = new JButton("显示全部记录[A]");
    btnBrowseAll.setMnemonic(KeyEvent.VK_A);
    btnPrint = new JButton("打印[P]");
    btnPrint.setMnemonic(KeyEvent.VK_D);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.add(pnlSouth, BorderLayout.SOUTH);
    panel.add(pnlCenter, BorderLayout.CENTER);
    panel.add(pnlNorth, BorderLayout.NORTH);

    pnlNorth.add(lblInputName);
    pnlNorth.add(txtName);
    pnlNorth.add(btnQuery);
    pnlNorth.add(btnBrowseAll);
    pnlSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pnlSouth.add(btnPrint);
    pnlSouth.add(btnExit);
    pnlCenter.setLayout(new BorderLayout());

    // 创建标题边框对象
    TitledBorder tb = new TitledBorder("查询结果");
    pnlCenter.setBorder(tb);

    // 创建学生服务对象
    studentService = new StudentServicelmpl();
    // 获取全部学生列表
    students = studentService.findAllStudent();
    // 填充表格数据
    fillTableData();

    // 设置窗口大小
    setSize(600, 350);
    // 设置窗口不可调整大小
    setResizable(false);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("按姓名查询学生记录");
    // 设置窗口可见
    setVisible(true);
    // 设置窗口默认关闭操作
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【退出】按钮单击事件
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dispose();
        }
    });

    // 【打印】按钮单击事件
    btnPrint.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException e1) {
                e1.printStackTrace();
            }
        }
    });

    // 【查询】按钮单击事件
    btnQuery.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            doQuery();
        }
    });

    // 【显示全部记录】按钮单击事件
    btnBrowseAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            // 获取全部学生记录
            students = studentService.findAllStudent();
            // 填充表格数据
            fillTableData();
        }
    });

    // 【姓名】文本框按键事件
    txtName.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                doQuery();
            }
        }
    });

    // 表格单击事件
    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            // 获取当前行的行数
            int row = table.rowAtPoint(e.getPoint());
            // 选中鼠标单击的行
            table.setRowSelectionInterval(row, row);
            // 设置文本框内容
            txtName.setText(table.getValueAt(row, 1).toString());
        }
    });
}

/**
 * 查询方法
 */
private void doQuery() {
    // 获取查询姓名
    String name = txtName.getText().trim();
    if (!name.equals("")) {
        // 按姓名查询获取学生列表
        students = studentService.findStudentByName(name);
        // 填充表格
        fillTableData();
    } else {
        JOptionPane.showMessageDialog(this, "请输入待查学生姓名!", "警告", JOptionPane.WARNING_MESSAGE);
        txtName.requestFocus();
    }
}

/**
 * 填充表格方法
 */
private void fillTableData() {
    // 填充表头
    colHead.clear();
    colHead.add("姓名");
    colHead.add("姓名");
    colHead.add("性别");
    colHead.add("年龄");
    colHead.add("系部");
    colHead.add("班级");
    colHead.add("电话");

    // 填充表记录
    rows.clear();
    for (Student student : students) {
        Vector currentRow = new Vector();
        currentRow.addElement(student.getId());
        currentRow.addElement(student.getName());
        currentRow.addElement(student.getSex());
        currentRow.addElement(student.getAge() + "");
        currentRow.addElement(student.getDepartment());
        currentRow.addElement(student.getClazz());
        currentRow.addElement(student.getTelephone());
        // 将当前行添加到记录行集
        rows.add(currentRow);
    }

    // 创建表格(参数1:记录集;参数2:表头)
    table = new JTable(rows, colHead);

    // 定义滚动面板
    scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // 将滚动面板添加到中心面板
    pnlCenter.add(scroller, BorderLayout.CENTER);

    // 重绘窗体
    repaint();

    // 判断是否有记录行
    if (rows.isEmpty()) {
        JOptionPane.showMessageDialog(this, "没有符合条件的记录!", "错误提示", JOptionPane.WARNING_MESSAGE);
        txtName.setText("");
    } else {
        // 让滚动条移到最上方
        scroller.getVerticalScrollBar().setValue(0);
    }
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    new FindStudentsByNameFrame("");
}

}
运行的结果,如下
第六天实训:学生信息管理系统_第1张图片
15)按班级查询学生窗口FindStudentsByClass
package net.zzm.student.gui;
import net.zzm.student.bean.Student;
import net.zzm.student.service.StudentService;
import net.zzm.student.service.impl.StudentServicelmpl;

import javax.swing.;
import javax.swing.border.TitledBorder;
import java.awt.
;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.util.Vector;
import java.util.List;
/**

  • 功能:按班级查询学生记录
  • 作者:张正敏
  • 日期:2019年6月23日
    */

public class FindStudentsByClassFrame extends JFrame {
/**
* 班级标签
/
private JLabel lblInputClass;
/
*
* 班级文本框
/
private JTextField txtClass;
/
*
* 面板
/
private JPanel panel;
private JPanel pnlSouth;
private JPanel pnlCenter;
private JPanel pnlNorth;
/
*
* 按钮
/
private JButton btnQuery;
private JButton btnBrowseAll;
private JButton btnPrint;
private JButton btnExit;
/
*
* 记录行集
/
private Vector rows;
/
*
* 表格列标题
/
private Vector colHead;
/
*
* 表格
/
private JTable table;
/
*
* 滚动面板
*/
private JScrollPane scroller;

/**
 * 当前记录行号
 */
private int currentRow;
/**
 * 学生列表
 */
private List students;
/**
 * 创建学生服务对象
 */
private StudentService studentService;

/**
 * 构造方法
 *
 * @param title
 */
public FindStudentsByClassFrame(String title) {
    super(title);
    intiGUI();
}

/**
 * 初始化用户界面
 */
private void intiGUI() {
    // 创建组件
    panel = (JPanel) getContentPane();
    pnlNorth = new JPanel();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();

    rows = new Vector();
    colHead = new Vector();

    lblInputClass = new JLabel("输入班级:");
    txtClass = new JTextField(10);
    txtClass.setHorizontalAlignment(JTextField.CENTER);
    btnQuery = new JButton("查询[Q]");
    btnQuery.setMnemonic(KeyEvent.VK_Q);
    btnBrowseAll = new JButton("显示全部记录[A]");
    btnBrowseAll.setMnemonic(KeyEvent.VK_A);
    btnPrint = new JButton("打印[P]");
    btnPrint.setMnemonic(KeyEvent.VK_D);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.add(pnlSouth, BorderLayout.SOUTH);
    panel.add(pnlCenter, BorderLayout.CENTER);
    panel.add(pnlNorth, BorderLayout.NORTH);

    pnlNorth.add(lblInputClass);
    pnlNorth.add(txtClass);
    pnlNorth.add(btnQuery);
    pnlNorth.add(btnBrowseAll);
    pnlSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pnlSouth.add(btnPrint);
    pnlSouth.add(btnExit);
    pnlCenter.setLayout(new BorderLayout());

    // 创建标题边框对象
    TitledBorder tb = new TitledBorder("查询结果");
    pnlCenter.setBorder(tb);

    // 创建学生服务对象
    studentService = new StudentServicelmpl();
    // 获取全部学生列表
    students = studentService.findAllStudent();
    // 填充表格数据
    fillTableData();

    // 设置窗口大小
    setSize(600, 350);
    // 设置窗口不可调整大小
    setResizable(false);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("按姓名查询学生记录");
    // 设置窗口可见
    setVisible(true);
    // 设置窗口默认关闭操作
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【退出】按钮单击事件
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dispose();
        }
    });

    // 【打印】按钮单击事件
    btnPrint.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException e1) {
                e1.printStackTrace();
            }
        }
    });

    // 【查询】按钮单击事件
    btnQuery.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            doQuery();
        }
    });

    // 【显示全部记录】按钮单击事件
    btnBrowseAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            // 获取全部学生记录
            students = studentService.findAllStudent();
            // 填充表格数据
            fillTableData();
        }
    });

    // 【班级】文本框按键事件
    txtClass.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                doQuery();
            }
        }
    });

    // 表格单击事件
    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            // 获取当前行的行数
            int row = table.rowAtPoint(e.getPoint());
            // 选中鼠标单击的行
            table.setRowSelectionInterval(row, row);
            // 设置文本框内容
            txtClass.setText(table.getValueAt(row, 5).toString());
        }
    });
}

/**
 * 查询方法
 */
private void doQuery() {
    // 获取查询班级
    String clazz = txtClass.getText().trim();
    if (!clazz.equals("")) {
        // 按班级查询获取学生列表
        students = studentService.findStudentByClass(clazz);
        // 填充表格
        fillTableData();
    } else {
        JOptionPane.showMessageDialog(this, "请输入待查班级!", "警告", JOptionPane.WARNING_MESSAGE);
        txtClass.requestFocus();
    }
}

/**
 * 填充表格方法
 */
private void fillTableData() {
    // 填充表头
    colHead.clear();
    colHead.add("班级");
    colHead.add("班级");
    colHead.add("性别");
    colHead.add("年龄");
    colHead.add("系部");
    colHead.add("班级");
    colHead.add("电话");

    // 填充表记录
    rows.clear();
    for (Student student : students) {
        Vector currentRow = new Vector();
        currentRow.addElement(student.getId());
        currentRow.addElement(student.getName());
        currentRow.addElement(student.getSex());
        currentRow.addElement(student.getAge() + "");
        currentRow.addElement(student.getDepartment());
        currentRow.addElement(student.getClazz());
        currentRow.addElement(student.getTelephone());
        // 将当前行添加到记录行集
        rows.add(currentRow);
    }

    // 创建表格(参数1:记录集;参数2:表头)
    table = new JTable(rows, colHead);

    // 定义滚动面板
    scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // 将滚动面板添加到中心面板
    pnlCenter.add(scroller, BorderLayout.CENTER);

    // 重绘窗体
    repaint();

    // 判断是否有记录行
    if (rows.isEmpty()) {
        JOptionPane.showMessageDialog(this, "没有符合条件的记录!", "错误提示", JOptionPane.WARNING_MESSAGE);
        txtClass.setText("");
    } else {
        // 让滚动条移到最上方
        scroller.getVerticalScrollBar().setValue(0);
    }
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    new FindStudentsByClassFrame("");
}

}

运行结果,如下
第六天实训:学生信息管理系统_第2张图片
16)按系部查询学生窗口FindStudentsByDepartment
package net.zzm.student.gui;
import net.zzm.student.bean.Student;
import net.zzm.student.service.StudentService;
import net.zzm.student.service.impl.StudentServicelmpl;

import javax.swing.;
import javax.swing.border.TitledBorder;
import java.awt.
;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.util.Vector;
import java.util.List;

public class FindStudentsByDepartmentFrame extends JFrame {
/**
* 系部标签
/
private JLabel lblInputDepartment;
/
*
* 系部文本框
/
private JTextField txtDepartment;
/
*
* 面板
/
private JPanel panel;
private JPanel pnlSouth;
private JPanel pnlCenter;
private JPanel pnlNorth;
/
*
* 按钮
/
private JButton btnQuery;
private JButton btnBrowseAll;
private JButton btnPrint;
private JButton btnExit;
/
*
* 记录行集
/
private Vector rows;
/
*
* 表格列标题
/
private Vector colHead;
/
*
* 表格
/
private JTable table;
/
*
* 滚动面板
*/
private JScrollPane scroller;

/**
 * 当前记录行号
 */
private int currentRow;
/**
 * 学生列表
 */
private List students;
/**
 * 创建学生服务对象
 */
private StudentService studentService;

/**
 * 构造方法
 *
 * @param title
 */
public FindStudentsByDepartmentFrame(String title) {
    super(title);
    intiGUI();
}

/**
 * 初始化用户界面
 */
private void intiGUI() {
    // 创建组件
    panel = (JPanel) getContentPane();
    pnlNorth = new JPanel();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();

    rows = new Vector();
    colHead = new Vector();

    lblInputDepartment = new JLabel("输入系部:");
    txtDepartment = new JTextField(10);
    txtDepartment.setHorizontalAlignment(JTextField.CENTER);
    btnQuery = new JButton("查询[Q]");
    btnQuery.setMnemonic(KeyEvent.VK_Q);
    btnBrowseAll = new JButton("显示全部记录[A]");
    btnBrowseAll.setMnemonic(KeyEvent.VK_A);
    btnPrint = new JButton("打印[P]");
    btnPrint.setMnemonic(KeyEvent.VK_D);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.add(pnlSouth, BorderLayout.SOUTH);
    panel.add(pnlCenter, BorderLayout.CENTER);
    panel.add(pnlNorth, BorderLayout.NORTH);

    pnlNorth.add(lblInputDepartment);
    pnlNorth.add(txtDepartment);
    pnlNorth.add(btnQuery);
    pnlNorth.add(btnBrowseAll);
    pnlSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pnlSouth.add(btnPrint);
    pnlSouth.add(btnExit);
    pnlCenter.setLayout(new BorderLayout());

    // 创建标题边框对象
    TitledBorder tb = new TitledBorder("查询结果");
    pnlCenter.setBorder(tb);

    // 创建学生服务对象
    studentService = new StudentServicelmpl();
    // 获取全部学生列表
    students = studentService.findAllStudent();
    // 填充表格数据
    fillTableData();

    // 设置窗口大小
    setSize(600, 350);
    // 设置窗口不可调整大小
    setResizable(false);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("按系部查询学生记录");
    // 设置窗口可见
    setVisible(true);
    // 设置窗口默认关闭操作
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【退出】按钮单击事件
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dispose();
        }
    });

    // 【打印】按钮单击事件
    btnPrint.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException e1) {
                e1.printStackTrace();
            }
        }
    });

    // 【查询】按钮单击事件
    btnQuery.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            doQuery();
        }
    });

    // 【显示全部记录】按钮单击事件
    btnBrowseAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            // 获取全部学生记录
            students = studentService.findAllStudent();
            // 填充表格数据
            fillTableData();
        }
    });

    // 【系部】文本框按键事件
    txtDepartment.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                doQuery();
            }
        }
    });

    // 表格单击事件
    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            // 获取当前行的行数
            int row = table.rowAtPoint(e.getPoint());
            // 选中鼠标单击的行
            table.setRowSelectionInterval(row, row);
            // 设置文本框内容
            txtDepartment.setText(table.getValueAt(row, 5).toString());
        }
    });
}

/**
 * 查询方法
 */
private void doQuery() {
    // 获取查询系部
    String department = txtDepartment.getText().trim();
    if (!department.equals("")) {
        // 按系部查询获取学生列表
        students = studentService.findStudentByDepartment(department);
        // 填充表格
        fillTableData();
    } else {
        JOptionPane.showMessageDialog(this, "请输入待查系部!", "警告", JOptionPane.WARNING_MESSAGE);
        txtDepartment.requestFocus();
    }
}

/**
 * 填充表格方法
 */
private void fillTableData() {
    // 填充表头
    colHead.clear();
    colHead.add("系部");
    colHead.add("系部");
    colHead.add("性别");
    colHead.add("年龄");
    colHead.add("系部");
    colHead.add("系部");
    colHead.add("电话");

    // 填充表记录
    rows.clear();
    for (Student student : students) {
        Vector currentRow = new Vector();
        currentRow.addElement(student.getId());
        currentRow.addElement(student.getName());
        currentRow.addElement(student.getSex());
        currentRow.addElement(student.getAge() + "");
        currentRow.addElement(student.getDepartment());
        currentRow.addElement(student.getClazz());
        currentRow.addElement(student.getTelephone());
        // 将当前行添加到记录行集
        rows.add(currentRow);
    }

    // 创建表格(参数1:记录集;参数2:表头)
    table = new JTable(rows, colHead);

    // 定义滚动面板
    scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // 将滚动面板添加到中心面板
    pnlCenter.add(scroller, BorderLayout.CENTER);

    // 重绘窗体
    repaint();

    // 判断是否有记录行
    if (rows.isEmpty()) {
        JOptionPane.showMessageDialog(this, "没有符合条件的记录!", "错误提示", JOptionPane.WARNING_MESSAGE);
        txtDepartment.setText("");
    } else {
        // 让滚动条移到最上方
        scroller.getVerticalScrollBar().setValue(0);
    }
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    new FindStudentsByDepartmentFrame("");
}

}
运行结果,如下
第六天实训:学生信息管理系统_第3张图片
17)按性别统计人数窗口CountStudentsBySex
package net.zzm.student.gui;
import net.zzm.student.service.StudentService;
import net.zzm.student.service.impl.StudentServicelmpl;

import javax.swing.;
import javax.swing.border.TitledBorder;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.print.PrinterException;
import java.util.Vector;
import java.util.List;

public class CountStudentsBySexFrame extends JFrame {
/**
* 面板
/
private JPanel panel;
private JPanel pnlSouth;
private JPanel pnlCenter;
/
*
* 按钮
/
private JButton btnPrint;
private JButton btnExit;
/
*
* 记录行集
/
private Vector rows;
/
*
* 表格列标题
/
private Vector colHead;
/
*
* 表格
/
private JTable table;
/
*
* 滚动面板
/
private JScrollPane scroller;
/
*
* 创建学生服务对象
*/
private StudentService studentService;

public CountStudentsBySexFrame(String title) {
    super(title);
    initGUI();
}

/**
 * 初始化用户界面
 */
private void initGUI() {
    // 创建组件
    panel = (JPanel) getContentPane();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();

    rows = new Vector();
    colHead = new Vector();

    btnPrint = new JButton("打印[P]");
    btnPrint.setMnemonic(KeyEvent.VK_P);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.add(pnlSouth, BorderLayout.SOUTH);
    panel.add(pnlCenter, BorderLayout.CENTER);

    pnlSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pnlSouth.add(btnPrint);
    pnlSouth.add(btnExit);
    pnlCenter.setLayout(new BorderLayout());

    TitledBorder tb = new TitledBorder("统计结果");
    pnlCenter.setBorder(tb);

    // 创建学生服务对象
    studentService = new StudentServicelmpl();
    // 获取按性别统计结果记录行集
    rows = studentService.findRowsBySex();
    // 设置表头
    colHead.add("性别");
    colHead.add("人数");

    // 创建表格(参数1:记录集;参数2:表头)
    table = new JTable(rows, colHead);
    scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pnlCenter.add(scroller, BorderLayout.CENTER);

    repaint(); // 重绘窗体

    if (rows.isEmpty()) {
        JOptionPane.showMessageDialog(this, "没有记录!", "错误提示", JOptionPane.WARNING_MESSAGE);
    }

    // 设置窗口大小
    setSize(300, 200);
    // 设置窗口不可调整大小
    setResizable(false);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("按性别统计学生人数");
    // 设置窗口可见
    setVisible(true);
    // 设置窗口默认关闭操作
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【退出】按钮单击事件
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            dispose();
        }
    });

    // 【打印】按钮单击事件
    btnPrint.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException e1) {
                e1.printStackTrace();
            }
        }
    });
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    new CountStudentsBySexFrame("");
}

}
运行结果,如下:
第六天实训:学生信息管理系统_第4张图片
18)按班级统计人数窗口CountStudentsByClass
package net.zzm.student.gui;
import net.zzm.student.service.StudentService;
import net.zzm.student.service.impl.StudentServicelmpl;

import javax.swing.;
import javax.swing.border.TitledBorder;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.print.PrinterException;
import java.util.Vector;

public class CountStudentsByClassFrame extends JFrame {
/**
* 面板
/
private JPanel panel;
private JPanel pnlSouth;
private JPanel pnlCenter;
/
*
* 按钮
/
private JButton btnPrint;
private JButton btnExit;
/
*
* 记录行集
/
private Vector rows;
/
*
* 表格列标题
/
private Vector colHead;
/
*
* 表格
/
private JTable table;
/
*
* 滚动面板
/
private JScrollPane scroller;
/
*
* 创建学生服务对象
*/
private StudentService studentService;

public CountStudentsByClassFrame(String title) {
    super(title);
    initGUI();
}

/**
 * 初始化用户界面
 */
private void initGUI() {
    // 创建组件
    panel = (JPanel) getContentPane();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();

    rows = new Vector();
    colHead = new Vector();

    btnPrint = new JButton("打印[P]");
    btnPrint.setMnemonic(KeyEvent.VK_P);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.add(pnlSouth, BorderLayout.SOUTH);
    panel.add(pnlCenter, BorderLayout.CENTER);

    pnlSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pnlSouth.add(btnPrint);
    pnlSouth.add(btnExit);
    pnlCenter.setLayout(new BorderLayout());

    TitledBorder tb = new TitledBorder("统计结果");
    pnlCenter.setBorder(tb);

    // 创建学生服务对象
    studentService = new StudentServicelmpl();
    // 获取按班级统计结果记录行集
    rows = studentService.findRowsByClass();
    // 设置表头
    colHead.add("班级");
    colHead.add("人数");

    // 创建表格(参数1:记录集;参数2:表头)
    table = new JTable(rows, colHead);
    scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pnlCenter.add(scroller, BorderLayout.CENTER);

    repaint(); // 重绘窗体

    if (rows.isEmpty()) {
        JOptionPane.showMessageDialog(this, "没有记录!", "错误提示", JOptionPane.WARNING_MESSAGE);
    }

    // 设置窗口大小
    setSize(300, 200);
    // 设置窗口不可调整大小
    setResizable(false);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("按班级统计学生人数");
    // 设置窗口可见
    setVisible(true);
    // 设置窗口默认关闭操作
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【退出】按钮单击事件
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            dispose();
        }
    });

    // 【打印】按钮单击事件
    btnPrint.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException e1) {
                e1.printStackTrace();
            }
        }
    });
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    new CountStudentsByClassFrame("");
}

}
运行结果,如下:
第六天实训:学生信息管理系统_第5张图片
19)按系部统计人数窗口CountStudentsByDepartment
package net.zzm.student.gui;
import net.zzm.student.service.StudentService;
import net.zzm.student.service.impl.StudentServicelmpl;

import javax.swing.;
import javax.swing.border.TitledBorder;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.print.PrinterException;
import java.util.Vector;

public class CountStudentsByDepartmentFrame extends JFrame {
/**
* 面板
/
private JPanel panel;
private JPanel pnlSouth;
private JPanel pnlCenter;
/
*
* 按钮
/
private JButton btnPrint;
private JButton btnExit;
/
*
* 记录行集
/
private Vector rows;
/
*
* 表格列标题
/
private Vector colHead;
/
*
* 表格
/
private JTable table;
/
*
* 滚动面板
/
private JScrollPane scroller;
/
*
* 创建学生服务对象
*/
private StudentService studentService;

public CountStudentsByDepartmentFrame(String title) {
    super(title);
    initGUI();
}

/**
 * 初始化用户界面
 */
private void initGUI() {
    // 创建组件
    panel = (JPanel) getContentPane();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();

    rows = new Vector();
    colHead = new Vector();

    btnPrint = new JButton("打印[P]");
    btnPrint.setMnemonic(KeyEvent.VK_P);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.add(pnlSouth, BorderLayout.SOUTH);
    panel.add(pnlCenter, BorderLayout.CENTER);

    pnlSouth.setLayout(new FlowLayout(FlowLayout.RIGHT));
    pnlSouth.add(btnPrint);
    pnlSouth.add(btnExit);
    pnlCenter.setLayout(new BorderLayout());

    TitledBorder tb = new TitledBorder("统计结果");
    pnlCenter.setBorder(tb);

    // 创建学生服务对象
    studentService = new StudentServicelmpl();
    // 获取按系部统计结果记录行集
    rows = studentService.findRowsByDepartment();
    // 设置表头
    colHead.add("系部");
    colHead.add("人数");

    // 创建表格(参数1:记录集;参数2:表头)
    table = new JTable(rows, colHead);
    scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pnlCenter.add(scroller, BorderLayout.CENTER);

    repaint(); // 重绘窗体

    if (rows.isEmpty()) {
        JOptionPane.showMessageDialog(this, "没有记录!", "错误提示", JOptionPane.WARNING_MESSAGE);
    }

    // 设置窗口大小
    setSize(300, 200);
    // 设置窗口不可调整大小
    setResizable(false);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("按班级统计学生人数");
    // 设置窗口可见
    setVisible(true);
    // 设置窗口默认关闭操作
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【退出】按钮单击事件
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            dispose();
        }
    });

    // 【打印】按钮单击事件
    btnPrint.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException e1) {
                e1.printStackTrace();
            }
        }
    });
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    new CountStudentsByDepartmentFrame("");
}

}
运行结果,如下:

第六天实训:学生信息管理系统_第6张图片
20)设置状态栏信息窗口SetStatusBarFrame
package net.zzm.student.gui;
import net.zzm.student.app.Application;
import net.zzm.student.bean.Status;
import net.zzm.student.service.StatusService;
import net.zzm.student.service.impl.StatusServiceImpl;

import javax.swing.;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

public class SetStatusBarFrame extends JFrame {
/**
* 面板
/
private JPanel panel;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JPanel panel4;
private JPanel panel5;
/
*
* 标签
/
private JLabel lblCollege;
private JLabel lblVersion;
private JLabel lblAuthor;
private JLabel lblTelephone;
private JLabel lblAddress;
private JLabel lblEmail;
/
*
* 文本框
/
private JTextField txtCollege;
private JTextField txtVersion;
private JTextField txtAuthor;
private JTextField txtTelephone;
private JTextField txtAddress;
private JTextField txtEmail;
/
*
* 按钮
/
private JButton btnSave;
private JButton btnExit;
/
*
* 状态服务对象
*/
private StatusService statusService;

/**
 * 构造方法
 *
 * @param title
 */
public SetStatusBarFrame(String title) {
    super(title);
    initGUI();
}

/**
 * 初始化用户界面
 */
private void initGUI() {
    // 创建组件
    panel = (JPanel) getContentPane();
    panel1 = new JPanel();
    panel2 = new JPanel();
    panel3 = new JPanel();
    panel4 = new JPanel();
    panel5 = new JPanel();

    lblCollege = new JLabel("校名:");
    lblVersion = new JLabel("版本:");
    lblAuthor = new JLabel("作者:");
    lblTelephone = new JLabel("电话:");
    lblAddress = new JLabel("地址:");
    lblEmail = new JLabel("邮件:");

    txtCollege = new JTextField(12);
    txtVersion = new JTextField(12);
    txtAuthor = new JTextField(12);
    txtTelephone = new JTextField(12);
    txtAddress = new JTextField(29);
    txtEmail = new JTextField(29);

    btnSave = new JButton("保存[S]");
    btnSave.setMnemonic(KeyEvent.VK_S);
    btnExit = new JButton("退出[X]");
    btnExit.setMnemonic(KeyEvent.VK_X);

    // 添加组件
    panel.setLayout(new GridLayout(5, 1));
    panel.add(panel1);
    panel.add(panel2);
    panel.add(panel3);
    panel.add(panel4);
    panel.add(panel5);

    panel1.add(lblCollege);
    panel1.add(txtCollege);
    panel1.add(lblVersion);
    panel1.add(txtVersion);

    panel2.add(lblAuthor);
    panel2.add(txtAuthor);
    panel2.add(lblTelephone);
    panel2.add(txtTelephone);

    panel3.add(lblAddress);
    panel3.add(txtAddress);
    panel4.add(lblEmail);
    panel4.add(txtEmail);

    panel5.add(btnSave);
    panel5.add(btnExit);

    // 创建状态服务对象
    statusService = new StatusServiceImpl();
    // 按标识符获取状态对象
    Status status = statusService.findStatusById(1);
    if (status != null) {
        txtCollege.setText(status.getCollege());
        txtVersion.setText(status.getVersion());
        txtAuthor.setText(status.getAuthor());
        txtAddress.setText(status.getAuthor());
        txtTelephone.setText(status.getTelephone());
        txtAddress.setText(status.getAddress());
        txtEmail.setText(status.getEmail());
    }

    // 设置窗口属性
    setResizable(false);
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 【关闭】按钮事件处理
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            dispose();
        }
    });

    // 【保存】按钮事件处理
    btnSave.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // 获取状态信息对象
            Status status = statusService.findStatusById(1);
            // 修改属性值
            status.setCollege(txtCollege.getText());
            status.setVersion(txtVersion.getText());
            status.setAuthor(txtAuthor.getText());
            status.setTelephone(txtTelephone.getText());
            status.setAddress(txtAddress.getText());
            status.setEmail(txtEmail.getText());
            // 更新状态记录
            int count = statusService.updateStatus(status);
            // 判断是否更新成功
            if (count > 0) {
                Application.mainFrame.setStatusBar();
                Application.mainFrame.setTitle("学生信息管理系统" + status.getVersion());
            }
        }
    });
}

/**
 * 主方法
 * @param args
 */
public static void main(String[] args) {
    new SetStatusBarFrame("");
}

}
要等到MainFrame类里写好setStatusBar()方法之后,才能测试该程序。
21)系统主窗口MainFrame(V1.1)
package net.zzm.student.gui;
/**

  • 功能:主界面窗口
  •  通过菜单栏息系统
    
  •   调用各个功能模块
    
  • 作者:张正敏
  • 日期:2019年6月20日
    */

import net.zzm.student.app.Application;
import net.zzm.student.bean.Status;
import net.zzm.student.service.StatusService;
import net.zzm.student.service.impl.StatusServiceImpl;

import javax.swing.;
import java.awt.
;
import java.awt.event.*;
import java.io.IOException;

public class MainFrame extends JFrame {

/**
 * 菜单部分
 */
private JMenuBar mnbMain;
/**
 * 设置菜单
 */
private JMenu mnuSet;
private JMenuItem mniSetCollegeInfo;
private JMenuItem mniSetStatusBar;
private JMenuItem mniChangePassword;
private JMenuItem mniExit;
/**
 * 操作菜单
 */
private JMenu mnuOperate;
private JMenuItem mniAddStudent;
private JMenuItem mniBrowseStudent;
private JMenuItem mniEditStudent;
/**
 * 删除菜单
 */
private JMenu mnuDelStu;
private JMenuItem mniDelStudentById;
private JMenuItem mniDelStudentsByClass;
private JMenuItem mniDelStudentsByDepartment;
/**
 * 查询菜单
 */
private JMenu mnuFind;
private JMenuItem mniFindStudentById;
private JMenuItem mniFindStudentsByName;
private JMenuItem mniFindStudentsByClass;
private JMenuItem mniFindStudentsByDepartment;
/**
 * 统计菜单
 */
private JMenu mnuCount;
private JMenuItem mniCountStudentsBySex;
private JMenuItem mniCountStudentsByClass;
private JMenuItem mniCountStudentsByDepartment;
/**
 * 帮助菜单
 */
private JMenu mnuHelp;
private JMenuItem mniHelp;
private JMenuItem mniAbout;
/**
 * 面板
 */
private JPanel panel;
private JPanel  pnlCenter;
private JPanel  pnlSouth;
/**
 * 状态栏标签
 */
private JLabel lblStatusBar;
/**
 * 背景标签
 */
private JLabel lblBackground;

/**
 * 图标对象
 */
private ImageIcon imgCollege;
private ImageIcon imgExit;
private ImageIcon imgPassword;
private ImageIcon imgQuery;
private ImageIcon imgBrowse;
private ImageIcon imgCount;
private ImageIcon imgBackground;
/**
 * 工具栏
 */
private JToolBar toolbar;
/**
 * 按钮
 */
private JButton btnSetCollege;
private JButton btnChangePassword;
private JButton btnFindStudentById;
private JButton btnExit;
private JButton btnBrowseStudent;
private JButton btnCountByDepartment;
/**
 * 状态对象
 */
private Status status;
/**
 * 状态服务对象
 */
private StatusService statusService;

/**
 * 构造方法
 *
 * @param title
 */
public MainFrame(String title) {
    super(title);
    initGUI();
}

/**
 * 初始化图形用户界面
 */
private void initGUI() {
    // 创建主菜单
    mnbMain = new JMenuBar();

    // 创建【设置】菜单及其菜单项
    mnuSet = new JMenu("系统设置[S]");
    mnuSet.setMnemonic(KeyEvent.VK_S);
    mniSetCollegeInfo = new JMenuItem("学校信息");
    mniSetStatusBar = new JMenuItem("状态栏信息");
    mniChangePassword = new JMenuItem("修改密码");
    mniExit = new JMenuItem("退出系统");

    // 创建【操作】菜单及其菜单项
    mnuOperate = new JMenu("数据操作[O]");
    mnuOperate.setMnemonic(KeyEvent.VK_O);
    mniAddStudent = new JMenuItem("增加学生表记录");
    mnuDelStu = new JMenu("删除学生表记录");
    mniEditStudent = new JMenuItem("编辑学生表记录");
    mniBrowseStudent = new JMenuItem("浏览学生表记录");

    // 创建【删除学生表记录】的子菜单
    mniDelStudentById = new JMenuItem("按学号删除");
    mniDelStudentsByClass = new JMenuItem("按班级删除");
    mniDelStudentsByDepartment = new JMenuItem("按系部删除");

    // 创建【查询】菜单及其菜单项
    mnuFind = new JMenu("查询学生[Q]");
    mnuFind.setMnemonic(KeyEvent.VK_Q);
    mniFindStudentById = new JMenuItem("按学号查询");
    mniFindStudentsByName = new JMenuItem("按姓名查询");
    mniFindStudentsByClass = new JMenuItem("按班级查询");
    mniFindStudentsByDepartment = new JMenuItem("按系部查询");

    // 创建【统计】菜单及其菜单项
    mnuCount = new JMenu("人数统计[C]");
    mnuCount.setMnemonic(KeyEvent.VK_C);
    mniCountStudentsBySex = new JMenuItem("按性别统计");
    mniCountStudentsByClass = new JMenuItem("按班级统计");
    mniCountStudentsByDepartment = new JMenuItem("按系部统计");

    // 创建【帮助】菜单及其菜单项
    mnuHelp = new JMenu("帮助[H]");
    mnuHelp.setMnemonic(KeyEvent.VK_H);
    mniHelp = new JMenuItem("帮助");
    mniAbout = new JMenuItem("关于");

    // 创建图标对象
    imgCollege = new ImageIcon("images/college.png");
    imgPassword = new ImageIcon("images/password.png");
    imgQuery = new ImageIcon("images/query.png");
    imgBrowse = new ImageIcon("images/browse.png");
    imgCount = new ImageIcon("images/count.png");
    imgExit = new ImageIcon("images/exit.png");

    // 创建工具栏
    toolbar = new JToolBar();
    btnSetCollege = new JButton("设置学校", imgCollege);
    btnSetCollege.setToolTipText("设置学校信息");
    btnSetCollege.setVerticalTextPosition(AbstractButton.BOTTOM);
    btnSetCollege.setHorizontalTextPosition(AbstractButton.CENTER);
    btnChangePassword = new JButton("修改密码", imgPassword);
    btnChangePassword.setToolTipText("修改用户密码");
    btnChangePassword.setVerticalTextPosition(AbstractButton.BOTTOM);
    btnChangePassword.setHorizontalTextPosition(AbstractButton.CENTER);
    btnBrowseStudent = new JButton("浏览学生", imgBrowse);
    btnBrowseStudent.setToolTipText("浏览学生记录");
    btnBrowseStudent.setVerticalTextPosition(AbstractButton.BOTTOM);
    btnBrowseStudent.setHorizontalTextPosition(AbstractButton.CENTER);
    btnFindStudentById = new JButton("查询学生", imgQuery);
    btnFindStudentById.setToolTipText("按学号查询学生记录");
    btnFindStudentById.setVerticalTextPosition(AbstractButton.BOTTOM);
    btnFindStudentById.setHorizontalTextPosition(AbstractButton.CENTER);
    btnCountByDepartment = new JButton("统计人数", imgCount);
    btnCountByDepartment.setToolTipText("按系部统计学生人数");
    btnCountByDepartment.setVerticalTextPosition(AbstractButton.BOTTOM);
    btnCountByDepartment.setHorizontalTextPosition(AbstractButton.CENTER);
    btnExit = new JButton("退出系统", imgExit);
    btnExit.setToolTipText("退出系统");
    btnExit.setVerticalTextPosition(AbstractButton.BOTTOM);
    btnExit.setHorizontalTextPosition(AbstractButton.CENTER);
    toolbar.add(btnSetCollege);
    toolbar.add(btnChangePassword);
    toolbar.add(btnBrowseStudent);
    toolbar.add(btnFindStudentById);
    toolbar.add(btnCountByDepartment);
    toolbar.add(btnExit);

    // 创建面板
    panel = (JPanel) getContentPane();
    pnlCenter = new JPanel();
    pnlSouth = new JPanel();
    pnlSouth.setLayout(new FlowLayout(FlowLayout.LEFT));

    // 创建背景图片
    imgBackground = new ImageIcon("images/background.jpg");
    // 创建背景标签
    lblBackground = new JLabel(imgBackground);
    // 创建状态栏标签
    lblStatusBar = new JLabel();

    // 设置菜单栏
    setJMenuBar(mnbMain);
    // 添加【设置】菜单
    mnbMain.add(mnuSet);
    mnuSet.add(mniSetCollegeInfo);
    mnuSet.add(mniSetStatusBar);
    mnuSet.add(mniChangePassword);
    mnuSet.addSeparator();
    mnuSet.add(mniExit);

    // 添加【删除学生表记录】菜单
    mnuDelStu.add(mniDelStudentById);
    mnuDelStu.add(mniDelStudentsByClass);
    mnuDelStu.add(mniDelStudentsByDepartment);

    // 添加【操作】菜单
    mnbMain.add(mnuOperate);
    mnuOperate.add(mniAddStudent);
    mnuOperate.add(mniEditStudent);
    mnuOperate.add(mnuDelStu);
    mnuOperate.add(mniBrowseStudent);

    // 添加【查询】菜单
    mnbMain.add(mnuFind);
    mnuFind.add(mniFindStudentById);
    mnuFind.add(mniFindStudentsByName);
    mnuFind.add(mniFindStudentsByClass);
    mnuFind.add(mniFindStudentsByDepartment);

    // 添加【统计】菜单
    mnbMain.add(mnuCount);
    mnuCount.add(mniCountStudentsBySex);
    mnuCount.add(mniCountStudentsByClass);
    mnuCount.add(mniCountStudentsByDepartment);

    // 添加【帮助】菜单
    mnbMain.add(mnuHelp);
    mnuHelp.add(mniHelp);
    mnuHelp.add(mniAbout);

    // 添加面板
    panel.setLayout(new BorderLayout());
    panel.add(toolbar, "North");
    panel.add(pnlCenter, "Center");
    panel.add(pnlSouth, "South");
    pnlCenter.add(lblBackground);
    pnlSouth.add(lblStatusBar);

    // 非管理员不能设置状态栏
    if (!Application.username.equals("admin")) {
        mniSetStatusBar.setEnabled(false);
        mniAddStudent.setEnabled(false);
        mnuDelStu.setEnabled(false);
        mniEditStudent.setEnabled(false);
    }

    // 设置状态栏信息
    setStatusBar();

    // 创建状态服务对象
    statusService = new StatusServiceImpl();
    // 获取状态对象
    status = statusService.findStatusById(1);

    // 设置窗口尺寸
    setSize(800, 640);
    // 设置窗口可见
    setVisible(true);
    // 设置窗口屏幕居中
    setLocationRelativeTo(null);
    // 设置窗口标题
    setTitle("学生信息管理系统" + status.getVersion());

    // 注册窗口监听器,继承窗口适配器,编写事件处理方法
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            exitSystem();
        }
    });

    // 设置菜单
    // 【设置学校信息】菜单项单击事件
    mniSetCollegeInfo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new SetCollegeInfoFrame("");
        }
    });

    // 【设置状态栏信息】菜单项单击事件
    mniSetStatusBar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new SetStatusBarFrame("");
        }
    });

    // 【修改密码】菜单项单击事件
    mniChangePassword.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new ChangePasswordFrame("");
        }
    });

    // 【退出系统】菜单项单击事件
    mniExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            exitSystem();
        }
    });

    // 查询菜单
    // 【按学号查询】菜单项单击事件
    mniFindStudentById.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new FindStudentByIdFrame("");
        }
    });

    // 【按姓名查询】菜单项单击事件
    mniFindStudentsByName.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new FindStudentsByNameFrame("");
        }
    });

    // 【按班级查询】菜单项单击事件
    mniFindStudentsByClass.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new FindStudentsByClassFrame("");
        }
    });

    // 【按系部查询】菜单项单击事件
    mniFindStudentsByDepartment.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new FindStudentsByDepartmentFrame("");
        }
    });

    // 统计菜单
    // 【按性别统计人数】菜单项单击事件
    mniCountStudentsBySex.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new CountStudentsBySexFrame("");
        }
    });

    // 【按班级统计人数】菜单项单击事件
    mniCountStudentsByClass.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new CountStudentsByClassFrame("");
        }
    });

    // 【按系部统计人数】菜单项单击事件
    mniCountStudentsByDepartment.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new CountStudentsByDepartmentFrame("");
        }
    });

    // 【增加学生记录】菜单项单击事件
    mniAddStudent.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new AddStudentFrame("");
        }
    });

    // 【按学号删除学生记录】菜单项单击事件
    mniDelStudentById.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new DeleteStudentByIdFrame("");
        }
    });

    // 【按班级删除学生记录】菜单项单击事件
    mniDelStudentsByClass.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new DeleteStudentsByClassFrame("");
        }
    });

    // 【按系部删除学生记录】菜单项单击事件
    mniDelStudentsByDepartment.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new DeleteStudentsByDepartmentFrame("");
        }
    });

    // 【编辑学生记录】菜单项单击事件
    mniEditStudent.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new EditStudentFrame("");
        }
    });

    // 【浏览学生记录】菜单项单击事件
    mniBrowseStudent.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new BrowseStudentFrame("");
        }
    });

    // 【帮助】菜单单击事件
    mniHelp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Runtime.getRuntime().exec("cmd /c start help/帮助文档.chm");
            } catch (IOException e1) {
                JOptionPane.showMessageDialog(null, e1.getMessage(), "学生信息管理系统", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    // 【关于】菜单单击事件
    mniAbout.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null,
                    "开发人员:" + status.getCollege() + "_" + status.getAuthor() + "\n联系电话:" + status.getTelephone()
                            + "\n电子邮箱:" + status.getEmail(),
                    "学生信息管理系统" + status.getVersion(), JOptionPane.INFORMATION_MESSAGE);
        }
    });

    // 工具栏按钮单击事件
    // 【设置学校信息】按钮
    btnSetCollege.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new SetCollegeInfoFrame("");
        }
    });

    // 【修改密码】按钮
    btnChangePassword.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new ChangePasswordFrame("");
        }
    });

    // 【浏览】按钮
    btnBrowseStudent.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new BrowseStudentFrame("");
        }
    });

    // 【查询】按钮
    btnFindStudentById.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new FindStudentByIdFrame("");
        }
    });

    // 【统计】按钮
    btnCountByDepartment.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new CountStudentsByDepartmentFrame("");
        }
    });

    // 【退出】按钮
    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exitSystem();
        }
    });
}

/**
 * 退出系统(询问用户是否要退出)
 */
private void exitSystem() {
    int choice = JOptionPane.showConfirmDialog(this,
            "您是否要退出系统?","学生信息管理系统", JOptionPane.YES_NO_OPTION);
    if (choice == JOptionPane.YES_OPTION) {
        System.exit(0);
    } else {
        // 卸载当前窗口
        dispose();
        // 重新显示主窗口
        Application.mainFrame = new MainFrame("学生信息管理系统" + status.getVersion());
    }
}

/**
 * 设置状态栏信息
 */
public void setStatusBar() {
    // 创建状态服务对象
    statusService = new StatusServiceImpl();
    // 获取状态栏对象
    status = statusService.findStatusById(1);
    // 设置状态栏标签
    lblStatusBar.setText(
            status.getCollege() + "学生信息管理系统" + status.getVersion() + "      作者:" + status.getAuthor() + "      地址:"
                    + status.getAddress() + "      电话:" + status.getTelephone() + "      邮箱:" + status.getEmail());
}

/**
 * 主方法
 *
 * @param args
 */
public static void main(String[] args) {
    Application.mainFrame = new MainFrame("");
}

}
下面,启动登录窗口,成功登录后,可以在主界面里通过菜单系统调用各个功能模块。
运行结果,如下:
第六天实训:学生信息管理系统_第7张图片
经过6天的实训,之前都没有打过这么多的代码,这次前面那些还是跟着老师打的,有照的老师打的,实在太多了,我承认其中有copy老师的。完成了happy,在这写这个学生管理系统中,我学习到了要,做什么都要有逻辑思维,一步一步来,在刚开始的时候跟着老师打,这样也不觉得代码很多,然后老师喊我们看着他的笔记自已尝试着写,我觉的代码好多啊,打完了过后,发现很多方法其实都是差不多的。我也在本次实训中收获了不少,巩固了一下本学期的基础知识。在打代码的过程中,我也有许多的不会,在打代码的过程中,很多的不会,都是在老师帮助下修改成功的。
本次实训代码已写完

你可能感兴趣的:(学习,学习,实训)