📄 bookqueryzonghe.java
字号:
package bookmanager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.sql.*; //引入包java.sql.*;import javax.swing.table.*; //引入包sqljavax.swing.table.*;import java.util.*; //引入包sqljava.util*;import java.awt.event.*;import com.borland.dbswing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class bookqueryzonghe extends JFrame { //定义结果集 ResultSet rs; //定义数据库操作对象 private DBManager db = new DBManager(); String searchType =new String(); Vector tempvector = new Vector(1, 1); //定义DefaultTableModel模型 DefaultTableModel model = new DefaultTableModel(); //定义JTable为DefaultTableModel的实例model模式 JTable jTableResult = new JTable(model); XYLayout xYLayout1 = new XYLayout(); JScrollPane jScrollPane1 = new JScrollPane(); JButton jBOK = new JButton(); ButtonGroup group=new ButtonGroup(); JLabel jLabel3 = new JLabel(); JTextField jTextFieldISBN = new JTextField(); JLabel jLabel1 = new JLabel(); JTextField jTextFieldname = new JTextField(); JLabel jLabel4 = new JLabel(); JComboBox jComboBoxtype = new JComboBox(); JLabel jLabel6 = new JLabel(); JLabel jLabel7 = new JLabel(); JTextField jTextFieldprice1 = new JTextField(); JLabel jLabel8 = new JLabel(); JTextField jTextFieldprice2 = new JTextField(); JLabel jLabel9 = new JLabel(); JTextField jTextFieldpress = new JTextField(); JComboBox jComboBoxjsj = new JComboBox(); JComboBox jComboBoxshuxue = new JComboBox(); public bookqueryzonghe() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { bookqueryzonghe bookqueryzonghe = new bookqueryzonghe(); } private void jbInit() throws Exception { xYLayout1.setWidth(683); xYLayout1.setHeight(707); this.getContentPane().setLayout(xYLayout1); jBOK.setText("查询"); jBOK.addMouseListener(new bookqueryzonghe_jBOK_mouseAdapter(this)); jBOK.setBackground(UIManager.getColor("inactiveCaptionText")); jBOK.setFont(new java.awt.Font("Dialog", 0, 16)); // model中加入列名 model.addColumn("ISBN号"); model.addColumn("书名"); model.addColumn("出版社"); model.addColumn("作者"); model.addColumn("版本号"); model.addColumn("出版日期"); model.addColumn("定价"); model.addColumn("类别"); model.addColumn("数量"); model.addColumn("所在仓库号"); this.getContentPane().setBackground(UIManager.getColor("inactiveCaptionText")); this.setTitle("教材信息查询"); jScrollPane1.getViewport().setBackground(UIManager.getColor("inactiveCaptionText")); jLabel3.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel3.setText("ISBN号"); jTextFieldISBN.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldISBN.setText(""); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("教材名称"); jTextFieldname.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldname.setText(""); jLabel4.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setText("类别"); jLabel6.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel6.setText("价格"); jLabel7.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel7.setText("从"); jTextFieldprice1.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldprice1.setText(""); jLabel8.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel8.setText("到"); jTextFieldprice2.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldprice2.setText(""); jLabel9.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel9.setText("出版社"); jTextFieldpress.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldpress.setText(""); jComboBoxtype.setFont(new java.awt.Font("Dialog", 0, 16)); jComboBoxtype.addActionListener(new bookqueryzonghe_jComboBoxtype_actionAdapter(this)); this.getContentPane().add(jTextFieldISBN, new XYConstraints(125, 27, 164, 30)); this.getContentPane().add(jLabel1, new XYConstraints(318, 31, 67, 31)); this.getContentPane().add(jTextFieldname, new XYConstraints(400, 24, 145, 33)); this.getContentPane().add(jLabel4, new XYConstraints(63, 81, 54, 36)); this.getContentPane().add(jLabel6, new XYConstraints(61, 143, 54, 32)); this.getContentPane().add(jLabel3, new XYConstraints(61, 21, 63, 36)); this.getContentPane().add(jComboBoxtype, new XYConstraints(124, 83, 167, 33)); this.getContentPane().add(jLabel7, new XYConstraints(122, 146, 27, -1)); this.getContentPane().add(jTextFieldprice1, new XYConstraints(142, 142, 85, 32)); this.getContentPane().add(jLabel8, new XYConstraints(237, 149, 29, 21)); this.getContentPane().add(jTextFieldprice2, new XYConstraints(256, 142, 82, 32)); this.getContentPane().add(jComboBoxshuxue, new XYConstraints(411, 85, 152, 28)); this.getContentPane().add(jComboBoxjsj, new XYConstraints(412, 77, 155, 31)); this.getContentPane().add(jTextFieldpress, new XYConstraints(409, 86, 140, 30)); this.getContentPane().add(jLabel9, new XYConstraints(323, 91, 70, 26)); this.getContentPane().add(jBOK, new XYConstraints(465, 146, 81, 28)); this.getContentPane().add(jScrollPane1, new XYConstraints(31, 203, 628, 456)); jScrollPane1.getViewport().add(jTableResult, null); jComboBoxtype.addItem("计算机类"); jComboBoxtype.addItem("数学"); jComboBoxjsj.setVisible(false); jComboBoxshuxue.setVisible(false); } //设置标签内容 //void setLabelText(String content){ //jLabel1.setText(content); //} //void setType(String i){ //searchType=i; //}//加载数据 void jBOK_mouseClicked(MouseEvent e) { String strSQL; // boolean isFirst = true; //检验书目是否存在 strSQL = "select * from books "; if (!jTextFieldISBN.getText().trim().equals("")) { if (isFirst) { strSQL = strSQL + " where ISBN='" + jTextFieldISBN.getText().trim() + "'"; isFirst = false; } else { strSQL = strSQL + " and ISBN='" + jTextFieldISBN.getText().trim() + "'"; } } if (!jTextFieldname.getText().trim().equals("")) { if (isFirst) { strSQL = strSQL + " where bookname='" + jTextFieldname.getText().trim() + "'"; isFirst = false; } else { strSQL = strSQL + " and bookname='" + jTextFieldname.getText().trim() + "'"; } } if (!jComboBoxtype.getSelectedItem().toString().trim().equals("")) { if (isFirst) { strSQL = strSQL + " where type='" + jComboBoxtype.getSelectedItem().toString().trim() + "'"; isFirst = false; } else { strSQL = strSQL + " and type='" + jComboBoxtype.getSelectedItem().toString().trim() + "'"; } } if (!jTextFieldpress.getText().trim().equals("")) { if (isFirst) { strSQL = strSQL + " where press='" + jTextFieldpress.getText().trim() + "'"; isFirst = false; } else { strSQL = strSQL + " and bookpress='" + jTextFieldpress.getText().trim() + "'"; } } if (!jTextFieldprice1.getText().trim().equals("")) { if (isFirst) { strSQL = strSQL + " where price>='" + jTextFieldprice1.getText().trim() + "'"; isFirst = false; } else { strSQL = strSQL + " and price>='" + jTextFieldprice1.getText().trim() + "'"; } } if (!jTextFieldprice2.getText().trim().equals("")) { if (isFirst) { strSQL = strSQL + " where price<='" + jTextFieldprice2.getText().trim() + "'"; isFirst = false; } else { strSQL = strSQL + " and price<='" + jTextFieldprice2.getText().trim() + "'"; } } rs = db.getResult(strSQL); boolean isexist = false; try { isexist = rs.first(); } catch (SQLException ex1) { JOptionPane.showMessageDialog(null, "ex1.toString() " + ex1.toString()); } //若书目不存在,提示警告信息提醒用户 if (!isexist) { JOptionPane.showMessageDialog(null, "书库中没有书目,请确认!"); return; } //若存在,执行以下操作 //清空model中的对象 for (int n = model.getRowCount() - 1; n >= 0; n--) model.removeRow(n); try { rs.beforeFirst(); while (rs.next()) { tempvector = new Vector(1, 1); tempvector.add(rs.getString("ISBN")); tempvector.add(rs.getString("name")); tempvector.add(rs.getString("Press")); tempvector.add(rs.getString("Author")); tempvector.add(rs.getString("type")); tempvector.add(rs.getString("Pressdate")); tempvector.add(rs.getString("Price")); tempvector.add(rs.getString("Vnum")); tempvector.add(rs.getString("num")); tempvector.add(rs.getString("roomnum")); model.addRow(tempvector); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "ex.toString() :" + ex.toString()); } } void jComboBoxtypedetailjsj_actionPerformed(ActionEvent e) { } void jComboBoxtype_actionPerformed(ActionEvent e) { }}class bookqueryzonghe_jBOK_mouseAdapter extends java.awt.event.MouseAdapter { bookqueryzonghe adaptee; bookqueryzonghe_jBOK_mouseAdapter(bookqueryzonghe adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jBOK_mouseClicked(e); }}class bookqueryzonghe_jComboBoxtypedetailjsj_actionAdapter implements java.awt.event.ActionListener { bookqueryzonghe adaptee; bookqueryzonghe_jComboBoxtypedetailjsj_actionAdapter(bookqueryzonghe adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jComboBoxtypedetailjsj_actionPerformed(e); }}class bookqueryzonghe_jComboBoxtype_actionAdapter implements java.awt.event.ActionListener { bookqueryzonghe adaptee; bookqueryzonghe_jComboBoxtype_actionAdapter(bookqueryzonghe adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jComboBoxtype_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -