?? banjixinxi.java
字號(hào):
package coursedesign;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.QueryResolver;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.sql.dataset.Load;
import com.borland.dbswing.JdbTable;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class banjixinxi
extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JComboBox jComboBox1 = new JComboBox();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryResolver queryResolver1 = new QueryResolver();
JdbTable jdbTable1 = new JdbTable();
public banjixinxi() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
setTitle("學(xué)生基本信息查詢");
this.getContentPane().setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleForeground"));
setSize(new Dimension(500, 400));
jComboBox1.setToolTipText("");
jComboBox1.addItem("請(qǐng)選擇查詢條件");
jComboBox1.addItem("學(xué)生信息");
jComboBox1.addItem("班級(jí)信息");
jComboBox1.addItem("選課信息");
jComboBox1.setSelectedItem(this);
database1.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa",
"zjxy2006", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver", null));
queryDataSet1.setQuery(new QueryDescriptor(database1,
"SELECT * FROM base_info", null, true,
Load.ALL));
jComboBox1.addActionListener(new banjixinxi_jComboBox1_actionAdapter(this));
this.getContentPane().add(jComboBox1, new XYConstraints(2, 1, 111, -1));
this.getContentPane().add(jdbTable1, new XYConstraints(1, 40, 497, 332));
jdbTable1.setDataSet(queryDataSet1);
}
public static void main(String[] args) {
banjixinxi banjixinxi = new banjixinxi();
}
public void jComboBox1_actionPerformed(ActionEvent e) {
int state = jComboBox1.getSelectedIndex();
if (state == 1) {
try {
String sql = "select * from base_info";
queryDataSet1.close();
//將SQL語句傳給queryDataSet1執(zhí)行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql, null, true,
Load.ALL));
queryDataSet1.open(); //將queryDataSet1打開
queryDataSet1.refresh(); //刷新queryDataSet1
} //end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Sorry!暫時(shí)沒有學(xué)生信息記錄");
} //end catch
} //end if
else {
if (state == 2) {
try {
String sql1 = "select * from class_info";
queryDataSet1.close();
//將SQL語句傳給queryDataSet1執(zhí)行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql1, null, true,
Load.ALL));
queryDataSet1.open(); //將queryDataSet1打開
queryDataSet1.refresh(); //刷新queryDataSet1
} //end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Sorry!暫時(shí)沒有班級(jí)信息記錄");
} //end catch
} //end if of else
else
{
try{
String sql2="select * from xuankebiao";
queryDataSet1.close();
//將SQL語句傳給queryDataSet1執(zhí)行。
queryDataSet1.setQuery(new QueryDescriptor(database1, sql2, null, true,Load.ALL));
queryDataSet1.open(); //將queryDataSet1打開
queryDataSet1.refresh();//刷新queryDataSet1
}//end try
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Sorry!暫時(shí)沒有課程信息記錄");
}//end catch
}//end else of else
}//end else
}
}
class banjixinxi_jComboBox1_actionAdapter
implements ActionListener {
private banjixinxi adaptee;
banjixinxi_jComboBox1_actionAdapter(banjixinxi adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jComboBox1_actionPerformed(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -