package view;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import dao.ClassDao;
import dao.DeptTypeDao;
import dao.MajorTypeDao;
import dao.StudentTypeDao;
import model.DepartmentType;
import model.MajorType;
import model.StudentClass;
import model.StudentType;
import util.StringUtil;
import java.awt.Color;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
public class StudentManageFrm extends JFrame {
private JTable studentListTable; //声明成员变量
private JTextField searchStudentNameTextField;
private JTextField searchClassTextField;
private JTextField editStudentNameTextField;
private JTextField editClassTextField;
private JTextField editStudentPasswordTextField;
private JRadioButton editStudentSexManRadioButton;
private JRadioButton editStudentSexFemalRadioButton;
private JRadioButton editStudentSexUnknownRadioButton;
private ButtonGroup sexButtonGroup;
private JTextField editStuNumberTextField;
private JTextField editStuBirthdayTextField;
private JTextField editXueTextField;
private JTextField editMajorTextField;
/**
* Create the frame.
*/
public StudentManageFrm() {
setTitle("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406");
setBounds(100, 100, 1010, 838);
JScrollPane scrollPane = new JScrollPane();
studentListTable = new JTable();
studentListTable.setBackground(Color.WHITE);
studentListTable.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"\u5B66\u751F\u7F16\u53F7", "\u59D3\u540D", "\u6027\u522B", "\u5B66\u53F7", "\u5B66\u9662", "\u73ED\u7EA7", "\u751F\u65E5", "\u5BC6\u7801", "\u5B66\u7C4D\u72B6\u6001"
}
) {
boolean[] columnEditables = new boolean[] {
false, false, false, false, false, false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
scrollPane.setViewportView(studentListTable);
JLabel label = new JLabel("\u5B66\u751F\u59D3\u540D\uFF1A");
label.setFont(new Font("宋体", Font.PLAIN, 14));
label.setIcon(new ImageIcon(StudentManageFrm.class.getResource("/images/xuesheng.png")));
searchStudentNameTextField = new JTextField();
searchStudentNameTextField.setColumns(10);
JLabel label_1 = new JLabel("\u6240\u5C5E\u73ED\u7EA7\uFF1A");
label_1.setFont(new Font("宋体", Font.PLAIN, 14));
label_1.setIcon(new ImageIcon(StudentManageFrm.class.getResource("/images/juxingkaobei.png")));
searchClassTextField = new JTextField();
searchClassTextField.setColumns(10);
JButton searchButton = new JButton("\u67E5\u8BE2");
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { //查询学生
StudentType sc=new StudentType();
sc.setStu_name(searchStudentNameTextField.getText().toString());
sc.setStu_class(searchClassTextField.getText().toString());
setTable(sc);
}
});
searchButton.setFont(new Font("宋体", Font.PLAIN, 14));
JLabel label_2 = new JLabel("\u5B66\u751F\u59D3\u540D\uFF1A");
label_2.setIcon(new ImageIcon(StudentManageFrm.class.getResource("/images/xuesheng.png")));
label_2.setFont(new Font("宋体", Font.PLAIN, 14));
editStudentNameTextField = new JTextField();
editStudentNameTextField.setColumns(10);
JLabel label_3 = new JLabel("\u5B66\u751F\u6027\u522B\uFF1A");
label_3.setFont(new Font("宋体", Font.PLAIN, 14));
editStudentSexManRadioButton = new JRadioButton("\u7537");
editStudentSexManRadioButton.setFont(new Font("宋体", Font.PLAIN, 14));
editStudentSexFemalRadioButton = new JRadioButton("\u5973");
editStudentSexFemalRadioButton.setFont(new Font("宋体", Font.PLAIN, 14));
editStudentSexUnknownRadioButton = new JRadioButton("\u4FDD\u5BC6");
editStudentSexUnknownRadioButton.setFont(new Font("宋体", Font.PLAIN, 14));
//添加按钮组,将性别三个按钮放在按钮组中,实现三选一
sexButtonGroup=new ButtonGroup();
sexButtonGroup.add(editStudentSexManRadioButton);
sexButtonGroup.add(editStudentSexFemalRadioButton);
sexButtonGroup.add(editStudentSexUnknownRadioButton);
JLabel label_4 = new JLabel("\u6240\u5C5E\u73ED\u7EA7\uFF1A");
label_4.setFont(new Font("宋体", Font.PLAIN, 14));
editClassTextField = new JTextField();
editClassTextField.setColumns(10);
JLabel label_5 = new JLabel("\u767B\u5F55\u5BC6\u7801\uFF1A");
label_5.setFont(new Font("宋体", Font.PLAIN, 14));
editStudentPasswordTextField = new JTextField();
editStudentPasswordTextField.setColumns(10);
JButton submitEditButton = new JButton("\u786E\u8BA4\u4FEE\u6539");
submitEditButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) { //确认修改学生事件
try {
submitEditStudentAct(ae);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
submitEditButton.setIcon(new ImageIcon(StudentManageFrm.class.getResource("/images/queren.png")));
submitEditButton.setFont(new Font("宋体", Font.PLAIN, 14));
JButton deleteStudentButton = new JButton("\u5220\u9664\u5B66\u751F");
deleteStudentButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) { //删除学生
deleteStuAct(ae);
}
});
deleteStudentButton.setFont(new Font("宋体", Font.PLAIN, 14));
JLabel label_6 = new JLabel("\u5B66\u53F7\uFF1A");
label_6.setFont(new Font("宋体", Font.PLAIN, 14));
editStuNumberTextField = new JTextField();
editStuNumberTextField.setColumns(10);
JLabel label_7 = new JLabel("\u5B66\u9662\uFF1A");
label_7.setFont(new Font("宋体", Font.PLAIN, 14));
JLabel label_8 = new JLabel("\u751F\u65E5\uFF1A");
label_8.setFont(new Font("宋体", Font.PLAIN, 14));
editStuBirthdayTextField = new JTextField();
editStuBirthdayTextField.setColumns(10);
editXueTextField = new JTextField();
editXueTextField.setColumns(10);
JLabel label_9 = new JLabel(" \u4E13\u4E1A\uFF1A");
label_9.setFont(new Font("宋体", Font.PLAIN, 14));
editMajorTextField = new JTextField();
editMajorTextField.setColumns(10);
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(124)
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(searchStudentNameTextField, GroupLayout.PREFERRED_SIZE, 135, GroupLayout.PREFERRED_SIZE)
.addGap(71)
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(searchClassTextField, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)
.addGap(96)
.addComponent(searchButton))
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addGap(158)
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(editStudentNameTextField, GroupLayout.