📄 booksquery.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package book_booking;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;//import java.io.*;//import java.util.*;import java.sql.*;public class BooksQuery extends JPanel implements ActionListener{ JTextField 书籍号,书名,作者,价格,出版社,库存量; JTextField 书籍号2,书名2,作者2,价格2,出版社2,库存量2; JButton 查询,清除; JButton 查询2,清除2; public BooksQuery() { 书籍号=new JTextField(10); 查询=new JButton("查询",new ImageIcon("D:/book_booking/image/74.jpg")); 清除=new JButton("清除",new ImageIcon("D:/book_booking/image/78.jpg")); 书籍号.addActionListener(this); 查询.addActionListener(this); 清除.addActionListener(this); 书名=new JTextField(10); 书名.setEditable(false); 作者=new JTextField(10); 作者.setEditable(false); 价格=new JTextField(10); 价格.setEditable(false); 出版社=new JTextField(10); 出版社.setEditable(false); 库存量=new JTextField(10); 库存量.setEditable(false); 书籍号2=new JTextField(10); 查询2=new JButton("查询",new ImageIcon("D:/book_booking/image/74.jpg")); 清除2=new JButton("清除",new ImageIcon("D:/book_booking/image/78.jpg")); 书籍号2.addActionListener(this); 查询2.addActionListener(this); 清除2.addActionListener(this); 书名2=new JTextField(10); 书名2.setEditable(false); 作者2=new JTextField(10); 作者2.setEditable(false); 价格2=new JTextField(10); 价格2.setEditable(false); 出版社2=new JTextField(10); 出版社2.setEditable(false); 库存量2=new JTextField(10); 库存量2.setEditable(false); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("输入要查询书籍的书籍号:",new ImageIcon("D:/book_booking/image/27.jpg"),JLabel.CENTER)); box1.add(书籍号); box1.add(查询); box1.add(清除); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("书名:",JLabel.CENTER)); box2.add(书名); Box box3=Box.createHorizontalBox(); box3.add(new JLabel("作者:",JLabel.CENTER)); box3.add(作者); Box box4=Box.createHorizontalBox(); box4.add(new JLabel("价格:",JLabel.CENTER)); box4.add(价格); Box box5=Box.createHorizontalBox(); box5.add(new JLabel("出版社:",JLabel.CENTER)); box5.add(出版社); Box box6=Box.createHorizontalBox(); box6.add(new JLabel("库存量:",JLabel.CENTER)); box6.add(库存量); Box box7=Box.createHorizontalBox(); box7.add(new JLabel("输入要查询采购单中书籍号:",new ImageIcon("D:/book_booking/image/27.jpg"),JLabel.CENTER)); box7.add(书籍号2); box7.add(查询2); box7.add(清除2); Box box8=Box.createHorizontalBox(); box8.add(new JLabel("书名:",JLabel.CENTER)); box8.add(书名2); Box box9=Box.createHorizontalBox(); box9.add(new JLabel("作者:",JLabel.CENTER)); box9.add(作者2); Box box10=Box.createHorizontalBox(); box10.add(new JLabel("价格:",JLabel.CENTER)); box10.add(价格2); Box box11=Box.createHorizontalBox(); box11.add(new JLabel("出版社:",JLabel.CENTER)); box11.add(出版社2); Box box12=Box.createHorizontalBox(); box12.add(new JLabel("库存量:",JLabel.CENTER)); box12.add(库存量2); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(box7); boxH.add(box8); boxH.add(box9); boxH.add(box10); boxH.add(box11); boxH.add(box12); boxH.add(Box.createVerticalGlue()); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout()); add(pCenter,BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { // 书籍号.setText(null); 书名.setText(null); 作者.setText(null); 价格.setText(null); 出版社.setText(null); 库存量.setText(null); 书名2.setText(null); 作者2.setText(null); 价格2.setText(null); 出版社2.setText(null); 库存量2.setText(null); if(e.getSource()==查询||e.getSource()==书籍号) { String number=""; number=书籍号.getText(); if(number.length()>0) { Boolean boo=false; try { SqlBean sqlBean1=new SqlBean(); String sqlStr="select * from books"; ResultSet result=sqlBean1.executeQuery(sqlStr); //Boolean boo=false; while(result.next()) { String snumber=result.getString("bookID"); if(snumber.equals(number)) { boo=true; 书名.setText(result.getString("bookName")); 作者.setText(result.getString("author")); 价格.setText(result.getString("price")); 出版社.setText(result.getString("press")); 库存量.setText(result.getString("bookCount")); } } sqlBean1.CloseDataBase(); } catch(SQLException ee) { } if(boo==false) { String warning="没有此书籍信息!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } else { String warning="必须输入书籍号!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } else if(e.getSource()==清除) { 书籍号.setText(null); 书名.setText(null); 作者.setText(null); 价格.setText(null); 出版社.setText(null); 库存量.setText(null); } if(e.getSource()==查询2||e.getSource()==书籍号2) { String number=""; number=书籍号2.getText(); if(number.length()>0) { Boolean boo=false; try { SqlBean sqlBean2=new SqlBean(); String sqlStr="select * from bookingList"; ResultSet result=sqlBean2.executeQuery(sqlStr); //Boolean boo=false; while(result.next()) { String snumber=result.getString("bookID"); if(snumber.equals(number)) { boo=true; 书名2.setText(result.getString("bookName")); 作者2.setText(result.getString("author")); 价格2.setText(result.getString("price")); 出版社2.setText(result.getString("press")); 库存量2.setText(result.getString("needCount")); } } sqlBean2.CloseDataBase(); } catch(SQLException ee) { } if(boo==false) { String warning="采购单中没有此书籍信息!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } else { String warning="必须输入书籍号!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } else if(e.getSource()==清除2) { 书籍号2.setText(null); 书名2.setText(null); 作者2.setText(null); 价格2.setText(null); 出版社2.setText(null); 库存量2.setText(null); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -