?? modifybooks.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 java.io.*;//import java.util.*;import java.sql.*;public class Modifybooks extends JPanel implements ActionListener{ JTextField 書籍號,書名,作者,價格,出版社,庫存量; JButton 開始修改,錄入修改,重置; public Modifybooks() { 書籍號=new JTextField(10); 書名=new JTextField(10); 作者=new JTextField(10); 價格=new JTextField(10); 出版社=new JTextField(10); 庫存量=new JTextField(10); 開始修改=new JButton("開始修改",new ImageIcon("D:/book_booking/image/33.jpg")); 錄入修改=new JButton("錄入修改",new ImageIcon("D:/book_booking/image/45.jpg")); 錄入修改.setEnabled(false); 重置=new JButton("重置",new ImageIcon("D:/book_booking/image/62.jpg")); 書籍號.addActionListener(this); 開始修改.addActionListener(this); 錄入修改.addActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("輸入要修改的書籍號:",new ImageIcon("D:/book_booking/image/48.jpg"),JLabel.CENTER)); 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 boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue()); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout()); add(pCenter,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(錄入修改); pSouth.add(重置); add(pSouth,BorderLayout.SOUTH); validate(); } public void actionPerformed(ActionEvent e) { Boolean boo=false; String name=""; String zuozhe=""; String jiage=""; String chubanshe=""; String kucun=""; if(e.getSource()==開始修改||e.getSource()==書籍號) { String number=""; number=書籍號.getText().trim(); if(number.length()>0) { try { SqlBean sqlBean1=new SqlBean(); String sqlStr="select * from books"; ResultSet result=sqlBean1.executeQuery(sqlStr); while(result.next()) { String snumber=result.getString("bookID"); if(snumber.equals(number)) { boo=true; 錄入修改.setEnabled(true); 書名.setText(result.getString("bookName")); 作者.setText(result.getString("author")); 價格.setText(result.getString("price")); 出版社.setText(result.getString("press")); 庫存量.setText(result.getString("bookCount")); } } sqlBean1.CloseDataBase(); } catch(Exception ee) { } if(boo==false) { String warning="該書籍號不存在!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 書籍號.setText(null); 書名.setText(null); 作者.setText(null); 價格.setText(null); 出版社.setText(null); 庫存量.setText(null); } } else { 錄入修改.setEnabled(false); String warning="必須輸入學號!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 書籍號.setText(null); 書名.setText(null); 作者.setText(null); 價格.setText(null); 出版社.setText(null); 庫存量.setText(null); } } else if(e.getSource()==錄入修改) { String number=""; number=書籍號.getText().trim(); if(number.length()>0) { try { SqlBean sqlBean2=new SqlBean(); String sqlStr="select * from books"; ResultSet result=sqlBean2.executeQuery(sqlStr); while(result.next()) { String snumber=result.getString("bookID"); if(snumber.equals(number)) { String question="該書籍基本信息已經存在,你想修改它的基本信息嗎?"; JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE); String m="該書籍基本信息將被修改!"; int ok=JOptionPane.showConfirmDialog(this,m,"確認",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { boo=true; name=書名.getText().trim(); zuozhe=作者.getText().trim(); jiage=價格.getText().trim(); chubanshe=出版社.getText().trim(); kucun=庫存量.getText().trim(); } else if(ok==JOptionPane.NO_OPTION) { 錄入修改.setEnabled(false); } } } sqlBean2.CloseDataBase(); } catch(Exception ee) { } if(boo==true) { try { SqlBean sqlBean3=new SqlBean(); String sqlStr1="update books set bookName = "+"'"+name+"',"+"author="+"'"+zuozhe+"',"+"price="+"'"+jiage+"',"+"press="+"'"+chubanshe+"',"+"bookCount="+"'"+kucun+"'"+"where bookID = "+"'"+number+"'"; int result1=sqlBean3.executeUpdate(sqlStr1); sqlBean3.CloseDataBase(); 書籍號.setText(null); 書名.setText(null); 作者.setText(null); 價格.setText(null); 出版社.setText(null); 庫存量.setText(null); } catch(Exception ee) { } } else if(boo==false) { String warning="沒有該書籍號基本信息,不能修改!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 錄入修改.setEnabled(false); } } else { String warning="必須輸入書籍號!"; JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 錄入修改.setEnabled(false); } } else if(e.getSource()==重置) { 書籍號.setText(null); 書名.setText(null); 作者.setText(null); 價格.setText(null); 出版社.setText(null); 庫存量.setText(null); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -