?? 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 + -