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