?? search.java~92~
字號:
package xscjgl;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import java.awt.Dimension;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import com.borland.dbswing.TableScrollPane;
import com.borland.dbswing.JdbTable;
import com.borland.dbswing.JdbNavToolBar;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.sql.dataset.Load;
import javax.swing.JOptionPane;
import java.util.concurrent.locks.Condition;
import java.awt.Font;
import com.sun.org.apache.xerces.internal.impl.dv.xs.StringDV;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class search extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JLabel jLabel2 = new JLabel();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JComboBox jComboBox1 = new JComboBox();
JComboBox jComboBox2 = new JComboBox();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
TableScrollPane tableScrollPane1 = new TableScrollPane();
XYLayout xYLayout3 = new XYLayout();
JdbTable jdbTable1 = new JdbTable();
DataModule1 dataModule11 = new DataModule1();
public search() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
dataModule11 = DataModule1.getDataModule();
getContentPane().setLayout(xYLayout1);
xYLayout1.setWidth(456);
xYLayout1.setHeight(346);
jPanel1.setLayout(xYLayout2);
jLabel1.setFont(new java.awt.Font("宋體", Font.BOLD, 15));
jLabel1.setToolTipText("");
jLabel1.setText("查詢學生,課程信息");
jLabel2.setText("請選擇查詢方式:");
jRadioButton1.setText("精確查詢");
jRadioButton2.setSelected(true);
jRadioButton2.setText("模糊查詢");
ButtonGroup group = new ButtonGroup();
jTextField1.setText("請輸入關鍵字");
jTextField1.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
jTextField1_mousePressed(e);
}
});
jButton1.setText("查詢");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox1_actionPerformed(e);
}
});
jPanel2.setLayout(xYLayout3);
jdbTable1.setDataSet(dataModule11.getStudent());
group.add(jRadioButton1);
group.add(jRadioButton2);
jPanel2.setBackground(new Color(236, 234, 255));
jPanel1.setBackground(new Color(241, 249, 249));
this.getContentPane().add(jPanel1, new XYConstraints(0, 10, 456, 113));
jPanel1.add(jRadioButton2, new XYConstraints(219, 34, -1, -1));
jPanel1.add(jLabel2, new XYConstraints(11, 38, -1, -1));
jPanel1.add(jRadioButton1, new XYConstraints(120, 34, -1, -1));
jPanel1.add(jComboBox1, new XYConstraints(11, 77, 119, -1));
jPanel1.add(jButton1, new XYConstraints(379, 75, -1, -1));
jPanel1.add(jTextField1, new XYConstraints(265, 78, 101, -1));
this.getContentPane().add(jPanel2, new XYConstraints( -1, 130, 458, 182));
jPanel2.add(tableScrollPane1, new XYConstraints(5, 0, 437, 162));
tableScrollPane1.getViewport().add(jdbTable1);
jPanel1.add(jComboBox2, new XYConstraints(134, 77, 124, -1));
jPanel1.add(jLabel1, new XYConstraints(116, 10, 165, 15));
jComboBox1.addItem("請選擇查詢類別");
jComboBox1.addItem("課程信息查詢");
jComboBox1.addItem("學生信息查詢");
jComboBox2.addItem("請選擇查詢條件");
}
public static void main(String[] args) {
search search = new search();
search.setVisible(true);
search.setLocationRelativeTo(null);
search.setSize(new Dimension(455,355));
}
public void jComboBox1_actionPerformed(ActionEvent e) {
//jComboBox1_change事件
int Select = jComboBox1.getSelectedIndex();
switch (Select)
{
case 1:
jComboBox2.removeAllItems();
jComboBox2.addItem("請選擇查詢條件");
jComboBox2.addItem("課程名");
jComboBox2.addItem("課程號");
jComboBox2.addItem("任課教師");
jComboBox2.addItem("上課時間");
jComboBox2.addItem("上課地點");
dataModule11.Query.close();
dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.database1, "select * from Course", null, true,
Load.ALL));
System.out.println("after change queryDataSet1, SQL is:" +
dataModule11.Query.getQuery());
dataModule11.Query.open();
dataModule11.Query.refresh();
break;
case 2:
jComboBox2.removeAllItems();
jComboBox2.addItem("請選擇查詢條件");
jComboBox2.addItem("學生姓名");
jComboBox2.addItem("學生籍貫");
jComboBox2.addItem("出生年月");
dataModule11.Query.close();
dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.database1, "select * from Student", null, true,
Load.ALL));
System.out.println("after change queryDataSet1, SQL is:" +
dataModule11.Query.getQuery());
dataModule11.Query.open();
dataModule11.Query.refresh();
break;
}
}
public void jTextField1_mousePressed(MouseEvent e) {
this.jTextField1.setText("");
}
public void jButton1_actionPerformed(ActionEvent e) {
//得到當前選中的類別
int Selected = jComboBox1.getSelectedIndex();
//得到當前選中的條件
int Condition = jComboBox2.getSelectedIndex();
int t=0;
String ClassID="";
String ConditionID="";
String selectCondition="";//SQL語句
String Keyvalue=jTextField1.getText().trim();
//如果沒有選擇
//*********************************************************************************
if(Selected==0)
{
JOptionPane.showMessageDialog(null,"請選擇查詢類別!");
t=1;
}else{
//*************************************************************************
if (Condition == 0) {
JOptionPane.showMessageDialog(null,"請選擇查詢條件!");
t=1;
}else{
//***************************************************************************
if(Keyvalue.equals("")||Keyvalue.equals("請輸入關鍵字"))
{
JOptionPane.showMessageDialog(null,"請輸入關鍵字!");
t=1;
jTextField1.setText("");
}else{
//判斷選擇的類別,為查詢語句提供表名。
switch(Selected){
case 1://課程信息查詢
ClassID="Course";
try{
switch (Condition) {
case 1:
ConditionID = "Cname";
break;
case 2:
ConditionID = "Cno";
break;
case 3:
ConditionID = "Cteacher";
case 4:
ConditionID = "Ctime";
break;
case 5:
ConditionID = "Caddress";
break;
}
}catch(Exception ex)
{
System.out.print("the first exception:" +
ex.getMessage());
}
break;
case 2:
ClassID="Student";
try{
switch (Condition) {
case 1:
ConditionID = "Sname";
break;
case 2:
ConditionID = "Sjg";
break;
case 3:
ConditionID = "Sbirth";
break;
}
}catch(Exception ex)
{
System.out.print("the third exception:"+ex.getMessage());
}
break;
}
//*********************************************************************************
//根據選擇條件得到最終的SQL語句
if(jRadioButton1.isSelected())
{
selectCondition = "select * from " + ClassID + " where " +
ConditionID + "='" + Keyvalue + "'";
// JOptionPane.showMessageDialog(null,"查詢條件為:" + selectCondition);
System.out.println("查詢條件為:" + selectCondition);
}else{
selectCondition = "select * from " + ClassID + " where " +
ConditionID + " like'%" + Keyvalue +
"%'";
//JOptionPane.showMessageDialog(null,"查詢條件為:" + selectCondition);
System.out.println("查詢條件為:" + selectCondition);
}//end third if else
//*********************************************************************************
}
//*****************************************************************
}//end second if else
//*************************************************************************
}//end first if else
//************************************************************************
//hava not change queryDataSet1
if (t == 0) {
try {
System.out.println("hava not change queryDataSet1, SQL is:" +
dataModule11.Query.getQuery());
//changge queryDataSet1
dataModule11.Query.close();
dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.
database1, selectCondition, null, true,
Load.ALL));
System.out.println("after change queryDataSet1, SQL is:" +
dataModule11.Query.getQuery());
//jdbTable1
dataModule11.Query.open();
dataModule11.Query.refresh();
if (dataModule11.Query.getRowCount() == 0) {
JOptionPane.showMessageDialog(null, "抱歉,沒有找到您要的信息!");
} else {
JOptionPane.showMessageDialog(null, "找到以下記錄");
}
} catch (Exception ex) {
System.out.println("exception is:" + ex.getMessage());
JOptionPane.showMessageDialog(null, "沒有找到您要的信息!");
}
}
//************************************************************************
//*********************************************************************************
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -