📄 studel.java~53~
字号:
String stubackground[] = {"", "初中", "高中", "大专", "本科", "研究生", "博士"};
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JComboBox cbostubirthdaymonth = new JComboBox(stubirthdaymonth);
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JComboBox cbostubirthdaydate = new JComboBox(stubirthdaydate);
JLabel jLabel6 = new JLabel();
JTextField txtstuno = new JTextField();
JTextField txtstuname = new JTextField();
JLabel jLabel7 = new JLabel();
JTextField txtstuphoto = new JTextField();
JLabel jLabel8 = new JLabel();
JTextField txtstuidcard = new JTextField();
JLabel jLabel9 = new JLabel();
JComboBox cbostubirthdayyear = new JComboBox(stubirthdayyear);
JLabel jLabel10 = new JLabel();
JTextArea txasturemarks = new JTextArea();
JLabel jLabel11 = new JLabel();
JTextField txtstuschool = new JTextField();
JComboBox cbostusex = new JComboBox(stusex);
JTextField txtstuaddress = new JTextField();
JLabel jLabel12 = new JLabel();
JLabel jLabel13 = new JLabel();
JComboBox cbostuappearance = new JComboBox(stuappearance);
JLabel jLabel14 = new JLabel();
JLabel jLabel15 = new JLabel();
JButton btnstuselect = new JButton();
JButton btnstudel = new JButton();
JButton btnexit = new JButton();
String head[] = {"学号", "姓名", "性别", "班级编号", "身份证", "出生日期", "家庭地址", "联系电话",
"毕业学校", "最高学历", "状态", "备注"};
DefaultTableModel mod = new DefaultTableModel(head, 0);
JTable tbstu = new JTable(mod);
JTableHeader jTableHeader1 = tbstu.getTableHeader();
//状态
String stuappearancename = this.cbostuappearance.getSelectedItem().
toString();
//性别
String stusexname = this.cbostusex.getSelectedItem().toString();
//出生日期
String stubirthdaytime =
this.cbostubirthdayyear.getSelectedItem().toString() + "-" +
this.cbostubirthdaymonth.getSelectedItem().toString() + "-" +
this.cbostubirthdaydate.getSelectedItem().toString() + " ";
JComboBox cbostubackground = new JComboBox(stubackground);
JLabel jLabel16 = new JLabel();
JComboBox cboclassno = new JComboBox();
public void btnstuselect_actionPerformed(ActionEvent e) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
String daima =
"select stuno,stuname,stusex,stuclassno,stuidcard,stubirthday,stuaddress,stuphoto,stuschool,stubackground,stuappearance,sturemarks from stu where 1=1";
if (!this.txtstuno.getText().equals("")) {
daima += " and stuno = '" + this.txtstuno.getText() + "'";
}
if (!this.txtstuname.getText().equals("")) {
daima += " and stuname ='" +
this.txtstuname.getText() + "'";
}
if (!stusexname.equals("")) {
daima += " and stusex ='" + stusexname + "'";
}
if (!this.txtstuidcard.getText().equals("")) {
daima += " and stuidcard ='" + this.txtstuidcard.getText() +
"'";
}if(!this.cboclassno.getSelectedItem().toString().equals("")){
daima+=" and stuclassno = '"+this.cboclassno.getSelectedItem().toString()+"'";
}if(!this.cbostubirthdayyear.getSelectedItem().toString().equals("")){
daima+=" and stubirthday like '%"+this.cbostubirthdayyear.getSelectedItem().toString()+"%'";
}if(!this.cbostubirthdaymonth.getSelectedItem().toString().equals("")){
daima+= " and stubirthday like '%"+this.cbostubirthdaymonth.getSelectedItem().toString()+"%'";
}if(!this.cbostubirthdaydate.getSelectedItem().toString().equals("")){
daima+=" and stubirthday like '%"+this.cbostubirthdaydate.getSelectedItem().toString()+"%'";
}if(!this.txtstuaddress.getText().equals("")){
daima+=" and stuaddress like '%"+this.txtstuaddress.getText()+"%'";
}if(!this.txtstuphoto.getText().equals("")){
daima+=" and stuphoto like '%"+this.txtstuphoto.getText()+"%'";
}if(!this.txtstuschool.getText().equals("")){
daima+=" and stuschool like '%"+this.txtstuschool.getText()+"%'";
}if(!this.cbostubackground.getSelectedItem().toString().equals("")){
daima+=" and stubackground ='"+this.cbostubackground.getSelectedItem().toString()+"'";
}if(!this.cbostuappearance.getSelectedItem().toString().equals("")){
daima+=" and stuappearance = '"+this.cbostuappearance.getSelectedItem().toString()+"'";
}if(!this.txasturemarks.getText().toString().equals("")){
daima+=" and sturemarks like '%"+this.txasturemarks.getText().toString()+"%'";
}
PreparedStatement sql = nod.prepareStatement(daima);
ResultSet i = sql.executeQuery();
mod.setNumRows(0);
while (i.next()) {
Object j[] = {i.getString(1), i.getString(2), i.getString(3),
i.getString(4), i.getString(5), i.getString(6),
i.getString(7), i.getString(8), i.getString(9),
i.getString(10), i.getString(11), i.getString(12)};
mod.addRow(j);
}
tbstu.updateUI();
i.close();
sql.close();
nod.close();
} catch (Exception ex) {
}
}
public void tbstu_mouseClicked(MouseEvent e) {
int row = this.tbstu.getSelectedRow();
if (row > -1) {
this.txtstuno.setText(this.tbstu.getValueAt(row, 0).toString());
this.txtstuname.setText(this.tbstu.getValueAt(row, 1).toString());
this.cbostusex.setSelectedItem(this.tbstu.getValueAt(row, 2).
toString());
this.cboclassno.setSelectedItem(this.tbstu.getValueAt(row, 3).
toString());
this.txtstuidcard.setText(this.tbstu.getValueAt(row, 4).toString());
String stubirthday = this.tbstu.getValueAt(row, 5).toString();
this.cbostubirthdayyear.setSelectedItem(stubirthday.substring(0, 4));
this.cbostubirthdaymonth.setSelectedItem(stubirthday.substring(5, 7));
this.cbostubirthdaydate.setSelectedItem(stubirthday.substring(8, 10));
this.txtstuaddress.setText(this.tbstu.getValueAt(row, 6).toString());
this.txtstuphoto.setText(this.tbstu.getValueAt(row, 7).toString());
this.txtstuschool.setText(this.tbstu.getValueAt(row, 8).toString());
this.cbostubackground.setSelectedItem(this.tbstu.getValueAt(row, 9).
toString());
this.cbostuappearance.setSelectedItem(this.tbstu.getValueAt(row, 10).
toString());
this.txasturemarks.setText(this.tbstu.getValueAt(row, 11).toString());
}
}
public void btnstudel_actionPerformed(ActionEvent e) {
try {
int row = this.tbstu.getSelectedRow();
if (JOptionPane.showConfirmDialog(this, "你确定删除吗?", "删除提示",
JOptionPane.OK_CANCEL_OPTION) ==
JOptionPane.OK_OPTION) {
if (row < 0) {
JOptionPane.showMessageDialog(this, "请选择数据");
return;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection nod = DriverManager.getConnection(
"jdbc:odbc:studer");
PreparedStatement sql = nod.prepareStatement(
"delete from stu where stuno = ?");
sql.setString(1, this.tbstu.getValueAt(row, 0).toString());
int i = sql.executeUpdate();
if (i > 0) {
mod.removeRow(row);
JOptionPane.showMessageDialog(this, "删除成功");
} else {
JOptionPane.showMessageDialog(this, "删除失败");
}
sql.close();
nod.close();
}
} catch (Exception ex) {
}
}
}
class studel_tbstu_mouseAdapter extends MouseAdapter {
private studel adaptee;
studel_tbstu_mouseAdapter(studel adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.tbstu_mouseClicked(e);
}
}
class studel_btnstudel_actionAdapter implements ActionListener {
private studel adaptee;
studel_btnstudel_actionAdapter(studel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnstudel_actionPerformed(e);
}
}
class studel_btnstuselect_actionAdapter implements ActionListener {
private studel adaptee;
studel_btnstuselect_actionAdapter(studel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnstuselect_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -