?? addbooks.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.util.*;import java.sql.*;/** * * @author Administrator */public class Addbooks extends JPanel implements ActionListener{ JTextField bookid,bookname,bookauthor,bookprice,bookpress,booknum; JButton 錄入,重置;// JLabel jl = null; // ImageIcon img = null; public Addbooks() {// img = new ImageIcon("D:/book_booking/image/book"); //jl = new JLabel(img); //this.setLayout(new BorderLayout()); //this.add(jl, BorderLayout.CENTER); bookid=new JTextField(10); bookname=new JTextField(10); bookauthor=new JTextField(10); bookprice=new JTextField(10); bookpress=new JTextField(10); booknum=new JTextField(10); 錄入=new JButton("錄入",new ImageIcon("D:/book_booking/image/45.jpg")); 重置=new JButton("重置",new ImageIcon("D:/book_booking/image/62.jpg")); 錄入.addActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("書籍號:",JLabel.CENTER)); box1.add(bookid); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("書名:",JLabel.CENTER)); box2.add(bookname); Box box3=Box.createHorizontalBox(); box3.add(new JLabel("作者:",JLabel.CENTER)); box3.add(bookauthor); Box box4=Box.createHorizontalBox(); box4.add(new JLabel("價格:",JLabel.CENTER)); box4.add(bookprice); Box box5=Box.createHorizontalBox(); box5.add(new JLabel("出版社:",JLabel.CENTER)); box5.add(bookpress); Box box6=Box.createHorizontalBox(); box6.add(new JLabel("進貨量:",JLabel.CENTER)); box6.add(booknum); 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) { if(e.getSource()==錄入) { String number=""; number=bookid.getText().trim();// String count="";// int count=Integer.parseInt(booknum.getText().trim()); String count=booknum.getText().trim(); if(number.length()>0) { boolean boo=false; try{ SqlBean sqlBean1=new SqlBean(); String sqlStr="select * from books"; ResultSet result=sqlBean1.executeQuery(sqlStr); while(result.next()) { String snumber=""; snumber=result.getString("bookID"); if(snumber.equals(number)) { boo=true; //String warning="該書籍基本信息已經存在,請到修改頁面修改:"; //JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } sqlBean1.CloseDataBase(); } catch(Exception ee) { } if(boo==true) { String m="基本信息將被錄入!"; int ok=JOptionPane.showConfirmDialog(this,m,"確認",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { try { SqlBean sqlBean2=new SqlBean(); String sqlStr="update books set bookCount=bookCount+"+"'"+count+"'"+" where bookID="+"'"+number+"'"; int result=sqlBean2.executeUpdate(sqlStr); sqlBean2.CloseDataBase(); } catch(Exception ee) { } bookid.setText(null); bookname.setText(null); bookauthor.setText(null); bookprice.setText(null); bookpress.setText(null); booknum.setText(null); } } else if(boo==false) { String m="基本信息將被錄入!"; int ok=JOptionPane.showConfirmDialog(this,m,"確認",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { String name=bookname.getText(); String author=bookauthor.getText(); String price=bookprice.getText(); String press=bookpress.getText(); String num=booknum.getText(); try{ SqlBean sqlBean3=new SqlBean(); String sqlStr="insert into books values"+"("+"'"+number+"','"+name+"','"+author+"',"+price+",'"+press+"',"+num+")"; int result=sqlBean3.executeUpdate(sqlStr); sqlBean3.CloseDataBase(); } catch(Exception ee) { } bookid.setText(null); bookname.setText(null); bookauthor.setText(null); bookprice.setText(null); bookpress.setText(null); booknum.setText(null); } } } else { String warning="必須輸入書籍號!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); } } if(e.getSource()==重置) { bookid.setText(null); bookname.setText(null); bookauthor.setText(null); bookprice.setText(null); bookpress.setText(null); booknum.setText(null); } } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -