?? classq.java
字號:
package xiangmu;
import java.awt.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
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;
/**
* <p>Title: 第四學習小組-教學管理系統</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ClassQ extends JFrame {
String cols[]={" 班級編號"," 班級類別"," 所屬年級"," 班主任"," 開班日期"," 畢業日期"," 備 注"};
DefaultTableModel bg=new DefaultTableModel(cols,0);
public ClassQ() {
try {
jbInit();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(
"jdbc:odbc:xiangmu");
PreparedStatement sql = conn.prepareStatement(
"select ClassNo from ClassInfo");
ResultSet i = sql.executeQuery();
while (i.next()) {
this.cmbClassNo.addItem(i.getString(1));
//this.cmbStudentNo.addItem(i.getString(2));
}
} catch (Exception ex) {
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setResizable(false);
getContentPane().setLayout(null);
btnQuery.setBounds(new Rectangle(494, 7, 90, 33));
btnQuery.setFont(new java.awt.Font("宋體", Font.BOLD, 12));
btnQuery.setText("查 詢");
btnQuery.addActionListener(new ClassQ_btnQuery_actionAdapter(this));
cmbClassTerm.setBounds(new Rectangle(208, 5, 91, 33));
jLabel2.setFont(new java.awt.Font("宋體", Font.BOLD, 12));
jLabel2.setText("所屬年級:");
jLabel2.setBounds(new Rectangle(143, 18, 67, 15));
jScrollPane1.setBorder(border1);
jButton2.addActionListener(new ClassQ_jButton2_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(8, 46, 790, 402));
jLabel1.setFont(new java.awt.Font("宋體", Font.BOLD, 12));
jLabel1.setText("所屬班級:");
jLabel1.setBounds(new Rectangle(308, 13, 71, 20));
cmbClassNo.setBounds(new Rectangle(372, 5, 90, 33));
this.getContentPane().add(jScrollPane1);
this.getContentPane().add(jButton2);
this.getContentPane().add(btnQuery);
this.getContentPane().add(jLabel2);
this.getContentPane().add(cmbClassTerm);
this.getContentPane().add(jLabel1);
this.getContentPane().add(cmbClassNo);
jScrollPane1.getViewport().add(jTable1);
jButton2.setBounds(new Rectangle(594, 7, 90, 33));
jButton2.setFont(new java.awt.Font("宋體", Font.BOLD, 12));
jButton2.setText("退 出");
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS);
setTitle("教學管理系統-班級信息查詢");
}
JButton btnQuery = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel2 = new JLabel();
String term[] = {"", "S1", "S2", "Y2"};
JComboBox cmbClassTerm = new JComboBox(term);
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1 = new JTable(bg);
Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(170, 170, 170));
JLabel jLabel1 = new JLabel();
String classno[] = {""};
JComboBox cmbClassNo = new JComboBox(classno);
public void jButton2_actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(this, "是否確定退出班級信息查詢", "溫馨提示",
JOptionPane.OK_CANCEL_OPTION) ==
JOptionPane.OK_OPTION) {
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
this.dispose();
}
}
public void btnQuery_actionPerformed(ActionEvent e) {
try {
String sql="select * from ClassInfo where 1=1 ";
if (!this.cmbClassTerm.getSelectedItem().toString().equals("")) {
sql += " and Term ='" +
this.cmbClassTerm.getSelectedItem().toString() + "'";
}
if (!this.cmbClassNo.getSelectedItem().toString().equals("")) {
sql += " and ClassNo ='" +
this.cmbClassNo.getSelectedItem().toString() + "'";
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:xiangmu");
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs= ps.executeQuery();
bg.setRowCount(0);
while(rs.next()){
Object val[]={rs.getString(1),rs.getString(2),
rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),
rs.getString(7)};
bg.addRow(val);
}
jTable1.updateUI();
rs.close();
ps.close();
conn.close();
}
catch (Exception ex) {
JOptionPane.showMessageDialog(this, "查詢失敗!");
}
}
}
class ClassQ_btnQuery_actionAdapter implements ActionListener {
private ClassQ adaptee;
ClassQ_btnQuery_actionAdapter(ClassQ adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnQuery_actionPerformed(e);
}
}
class ClassQ_jButton2_actionAdapter implements ActionListener {
private ClassQ adaptee;
ClassQ_jButton2_actionAdapter(ClassQ adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -