📄 classselect.java~3~
字号:
package java_教务管理系统;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import javax.swing.table.JTableHeader;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Connection;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class classselect extends JPanel {
public classselect() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jLabel1.setText("月");
jLabel1.setBounds(new Rectangle(212, 251, 12, 15));
jLabel2.setText("月");
jLabel2.setBounds(new Rectangle(212, 224, 12, 15));
jLabel3.setText("年");
jLabel3.setBounds(new Rectangle(138, 251, 12, 15));
cboclassSemester.setBounds(new Rectangle(332, 196, 63, 23));
jLabel4.setText("班级类别:");
jLabel4.setBounds(new Rectangle(406, 200, 60, 15));
jLabel5.setText("开学时间:");
jLabel5.setBounds(new Rectangle(6, 223, 60, 15));
cboclasscategory.setBounds(new Rectangle(470, 196, 73, 23));
tbclass.setBounds(new Rectangle(7, 26, 578, 166));
tbclass.addMouseListener(new classselect_tbclass_mouseAdapter(this));
jLabel6.setText("班主任:");
jLabel6.setBounds(new Rectangle(138, 199, 48, 15));
txaclassRemarks.setBounds(new Rectangle(367, 225, 176, 45));
cboendtimeyear.setBounds(new Rectangle(68, 247, 63, 23));
cbobeginstimedate.setBounds(new Rectangle(230, 220, 51, 23));
cbobeginstimeyear.setBounds(new Rectangle(68, 220, 63, 23));
cbobeginstimemonth.setBounds(new Rectangle(154, 220, 52, 23));
jLabel7.setText("毕业时间:");
jLabel7.setBounds(new Rectangle(5, 251, 60, 15));
jLabel8.setText("学期:");
jLabel8.setBounds(new Rectangle(291, 200, 36, 15));
cboendtimemonth.setBounds(new Rectangle(154, 247, 52, 23));
jLabel9.setText("备注:");
jLabel9.setBounds(new Rectangle(326, 223, 36, 15));
cboendtimedate.setBounds(new Rectangle(230, 247, 51, 23));
txtclassmastername.setBounds(new Rectangle(187, 196, 97, 20));
jLabel10.setText("年");
jLabel10.setBounds(new Rectangle(138, 224, 12, 15));
jLabel11.setText("班级编号:");
jLabel11.setBounds(new Rectangle(7, 198, 66, 15));
txtclassno.setBounds(new Rectangle(68, 196, 65, 20));
jTableHeader1.setBounds(new Rectangle(7, 0, 577, 29));
btnselect.setBounds(new Rectangle(127, 282, 81, 23));
btnselect.setText("搜索班级");
btnselect.addActionListener(new classselect_btnselect_actionAdapter(this));
brnexit.setBounds(new Rectangle(304, 283, 81, 23));
brnexit.setText("退出搜索");
this.add(jLabel1);
this.add(jLabel2);
this.add(jLabel3);
this.add(cboclassSemester);
this.add(jLabel4);
this.add(jLabel5);
this.add(cboclasscategory);
this.add(tbclass);
this.add(jLabel6);
this.add(txaclassRemarks);
this.add(cboendtimeyear);
this.add(cbobeginstimedate);
this.add(cbobeginstimeyear);
this.add(cbobeginstimemonth);
this.add(jLabel7);
this.add(jLabel8);
this.add(cboendtimemonth);
this.add(jLabel9);
this.add(cboendtimedate);
this.add(txtclassmastername);
this.add(jLabel10);
this.add(jLabel11);
this.add(txtclassno);
this.add(jTableHeader1);
this.add(btnselect);
this.add(brnexit);
}
//班级年级
String Semester[] = {"", "S1", "S2", "Y2"};
//班级类别
String category[] = {"", "脱产班", "周末班"};
//开学时间(年)
String beginstimeyear[] = {"", "2006", "2007", "2008", "2009"};
//开学时间(月)
String beginstimemonth[] = {"", "01", "02", "03", "04", "05", "06", "07",
"08",
"09",
"10", "11", "12"};
//开学时间(日)
String beginstimedate[] = {"", "01", "02", "03", "04", "05", "06", "07",
"08",
"09",
"10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25",
"26", "27", "28", "29", "30", "31"};
//毕业时间(年)
String endtimeyear[] = {"", "2006", "2007", "2008", "2009"};
//毕业时间(月)
String endtimemonth[] = {"", "01", "02", "03", "04", "05", "06", "07", "08",
"09",
"10", "11", "12"};
//毕业时间(日)
String endtimedate[] = {"", "01", "02", "03", "04", "05", "06", "07", "08",
"09",
"10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25",
"26", "27", "28", "29", "30", "31"};
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JComboBox cboclassSemester = new JComboBox(Semester);
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JComboBox cboclasscategory = new JComboBox(category);
String Head[] = {"班级编号", "班主任姓名", "班级类型", "学期", "开学时间", "毕业时间", "备注"};
DefaultTableModel mod = new DefaultTableModel(Head, 0);
JTable tbclass = new JTable(mod);
JLabel jLabel6 = new JLabel();
JTextArea txaclassRemarks = new JTextArea();
JComboBox cboendtimeyear = new JComboBox(endtimeyear);
JComboBox cbobeginstimedate = new JComboBox(beginstimedate);
JComboBox cbobeginstimeyear = new JComboBox(beginstimeyear);
JComboBox cbobeginstimemonth = new JComboBox(beginstimemonth);
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JComboBox cboendtimemonth = new JComboBox(endtimemonth);
JLabel jLabel9 = new JLabel();
JComboBox cboendtimedate = new JComboBox(endtimedate);
JTextField txtclassmastername = new JTextField();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
JTextField txtclassno = new JTextField();
JTableHeader jTableHeader1 = tbclass.getTableHeader();
JButton btnselect = new JButton();
JButton brnexit = new JButton();
//班级类别classcategory
String categoryname = this.cboclasscategory.getSelectedItem().
toString();
//学期classSemester
String Semestername = this.cboclassSemester.getSelectedItem().
toString();
//开学时间(年,月,日)
String beginstimenameyear = this.cbobeginstimeyear.getSelectedItem().
toString();
String beginstimenamemonth = this.cbobeginstimemonth.
getSelectedItem().
toString();
String beginstimenamedate = this.cbobeginstimedate.getSelectedItem().
toString();
//毕业时间(年,月,日)
String endtimenameyear = this.cboendtimeyear.getSelectedItem().
toString();
String endtimenamemonth = this.cboendtimemonth.getSelectedItem().
toString();
String endtimenamedate = this.cboendtimedate.getSelectedItem().
toString();
//开学时间
String beginstimename =
this.cbobeginstimeyear.getSelectedItem().toString() + "-" +
this.cbobeginstimemonth.getSelectedItem().toString() + "-" +
this.cbobeginstimedate.getSelectedItem().toString() + " ";
//毕业时间
String endtimename =
this.cboendtimeyear.getSelectedItem().toString() + "-" +
this.cboendtimemonth.getSelectedItem().toString() + "-" +
this.cboendtimedate.getSelectedItem().toString() + " ";
public void btnselect_actionPerformed(ActionEvent e) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
String daima = "select classno,classmastername,classcategory,classSemester,beginstime,endtime,classRemarks from class where 1=1";
if (!this.txtclassno.getText().equals("")) {
daima += " and classno = '" + this.txtclassno.getText() + "'";
}
if (!this.txtclassmastername.getText().equals("")) {
daima += " and classmastername ='" +
this.txtclassmastername.getText() + "'";
}
if (!categoryname.equals("")) {
daima += " and classcategory ='" + categoryname + "'";
}
if (!Semestername.equals("")) {
daima += " and classSemester='" + Semestername + "'";
}
if (!beginstimenameyear.equals("")) {
daima += " and beginstime like '%" + beginstimenameyear + "%'";
}
if (!beginstimenamemonth.equals("")) {
daima += " and beginstime like '%" + beginstimenamemonth + "%'";
}
if (!beginstimenamedate.equals("")) {
daima += " and beginstime like '%" + beginstimenamedate + "%'";
}
if (!endtimenameyear.equals("")) {
daima += " and endtime like '%" + endtimenameyear + "%'";
}
if (!endtimenamemonth.equals("")) {
daima += " and endtime like '%" + endtimenamemonth + "%'";
}
if (!endtimenamedate.equals("")) {
daima += " and endtime like '%" + endtimenamedate + "%'";
}
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)};
mod.addRow(j);
}
tbclass.updateUI();
i.close();
sql.close();
nod.close();
} catch (Exception ex) {
}
}
public void tbclass_mouseClicked(MouseEvent e) {
int row = this.tbclass.getSelectedRow();
if (row > -1) {
this.txtclassno.setText(this.tbclass.getValueAt(row, 0).toString());
this.txtclassmastername.setText(this.tbclass.getValueAt(row, 1).
toString());
this.cboclasscategory.setSelectedItem(this.tbclass.getValueAt(row,
2).
toString());
this.cboclassSemester.setSelectedItem(this.tbclass.getValueAt(row,
3).toString());
String beginstime = this.tbclass.getValueAt(row, 4).toString();
this.cbobeginstimeyear.setSelectedItem(beginstime.substring(0, 4));
this.cbobeginstimemonth.setSelectedItem(beginstime.substring(5, 7));
this.cbobeginstimedate.setSelectedItem(beginstime.substring(8, 10));
String endtime = this.tbclass.getValueAt(row, 5).toString();
this.cboendtimeyear.setSelectedItem(endtime.substring(0, 4));
this.cboendtimemonth.setSelectedItem(endtime.substring(5, 7));
this.cboendtimedate.setSelectedItem(endtime.substring(8, 10));
this.txaclassRemarks.setText(this.tbclass.getValueAt(row, 6).
toString());
}
}
}
class classselect_tbclass_mouseAdapter extends MouseAdapter {
private classselect adaptee;
classselect_tbclass_mouseAdapter(classselect adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.tbclass_mouseClicked(e);
}
}
class classselect_btnselect_actionAdapter implements ActionListener {
private classselect adaptee;
classselect_btnselect_actionAdapter(classselect adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnselect_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -