




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;/ -class Tsgl public static void main(String args) dbframe db = new dbframe( 圖書管理程序);/ 圖書管理系統(tǒng)主界面class dbframe extends Frame implements ActionListener MenuBar daohang = new MenuBar(); /建立菜單欄Menu mfile
2、= new Menu( 功能 ); /建立“功能”菜單組Menu mhelp = new Menu( 幫助 ); /建立“幫助”菜單組MenuItem mdenglu = new MenuItem(登陸 );MenuItem mchaxun = new MenuItem(查詢 );MenuItem mtianjia = new MenuItem(添加 );MenuItem mshanchu = new MenuItem(刪除 );MenuItem mexit = new MenuItem(退出 );MenuItem mhelpp = new MenuItem(關于 );Denglu pdeng
3、lu=new Denglu();Ptianjia ptianjia = new Ptianjia();Pmain pmain = new Pmain();Pchaxun pchaxun = new Pchaxun();Pshanchu pshanchu = new Pshanchu();dbframe(String s) /在窗口上添加菜單選項setTitle(s);mfile.add(mdenglu);mfile.add(mtianjia);mfile.add(mchaxun);mfile.add(mshanchu);mfile.add(mexit);mhelp.add(mhelpp);da
4、ohang.add(mfile);daohang.add(mhelp);setMenuBar(daohang);add(pmain);addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0););setBounds(200, 200, 340, 250);setResizable(false);setVisible(true);mexit.addActionListener(this);mdenglu.addActionListener(this);mtianjia
5、.addActionListener(this);mchaxun.addActionListener(this);mshanchu.addActionListener(this);mhelpp.addActionListener(this);validate(); / 窗口事件監(jiān)聽public void actionPerformed(ActionEvent e) if (e.getSource() = mexit)System.exit(0);if(e.getSource()=mdenglu)removeAll();add(pdenglu);validate();if (e.getSourc
6、e() = mtianjia) removeAll();add(ptianjia);validate(); / 圖書添加功能if (e.getSource() = mchaxun) removeAll();add(pchaxun);validate(); / 圖書查詢功能if (e.getSource() = mshanchu) removeAll();add(pshanchu);validate(); / 圖書刪除功能if (e.getSource() = mhelpp) JOptionPane.showMessageDialog(this, 歡迎使用圖書管理系統(tǒng) , 關于本系統(tǒng) , JOp
7、tionPane.INFORMATION_MESSAGE); /各功能菜單事件監(jiān)聽/class Ptianjia extends Panel implements ActionListener TextField tname, tauthor, tpublish, tdate, tcomment;Label lname, lauthor, lpublish, ldate, lcomment;Button btn;Ptianjia() setLayout(null);btn = new Button( 添加 ); /創(chuàng)建“添加”按鈕tname = new TextField();tauthor
8、= new TextField();tpublish = new TextField();tdate = new TextField();tcomment = new TextField(); /創(chuàng)建5 個文本框lname = new Label( 書名 );lauthor = new Label( 作者 );lpublish = new Label( 出版社 );ldate = new Label( 出版日期 );lcomment = new Label( 評論 );add(lname);add(tname);add(lauthor);add(tauthor);add(lpublish);a
9、dd(tpublish);add(ldate);add(tdate);add(lcomment);add(tcomment);add(btn); /添加“按鈕”到窗口面板上lname.setBounds(10, 10, 70, 25);tname.setBounds(90, 10, 220, 25);lauthor.setBounds(10, 40, 70, 25);tauthor.setBounds(90, 40, 220, 25);lpublish.setBounds(10, 70, 70, 25);tpublish.setBounds(90, 70, 220, 25);ldate.set
10、Bounds(10, 100, 70, 25);tdate.setBounds(90, 100, 220, 25);lcomment.setBounds(10, 130, 70, 25);tcomment.setBounds(90, 130, 220, 25);btn.setBounds(130, 160, 70, 25); /設置按鈕位置btn.addActionListener(this); /設置按鈕監(jiān)聽setSize(340, 250); /設置窗口大小setBackground(Color.white); /設置窗口背景顏色setVisible(true);validate();pu
11、blic void actionPerformed(ActionEvent e) String sname = tname.getText();String sauthor = tauthor.getText();String spublish = tpublish.getText();String sdate = tdate.getText();String scomment = tcomment.getText();String insertstr = insert into bookvalues + ( + + sname + + , + + sauthor + + , + + spub
12、lish + + ,+ + sdate + + , + + scomment + + ); / SQL語句Connection con;Statement sta;ResultSet rs;try Class.forName(oracle.jdbc.driver.OracleDriver); /加載 JDBC驅(qū)動 catch (ClassNotFoundException ee) System.out.println( + ee);try con = DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl, sa,orc
13、l); /連接數(shù)據(jù)庫sta = con.createStatement();sta.executeUpdate(insertstr); /執(zhí)行 SQL語句con.close(); /關閉數(shù)據(jù)庫tname.setText();tauthor.setText();tpublish.setText();tdate.setText();tcomment.setText(); / 重新初始化文本框內(nèi)容 JOptionPane.showMessageDialog(this, 添加成功 , 圖書管理系統(tǒng) ,JOptionPane.INFORMATION_MESSAGE); catch (SQLExcepti
14、on eee) System.out.println( + eee);tname.setText();tauthor.setText();tpublish.setText();tdate.setText();tcomment.setText();JOptionPane.showMessageDialog(this, 添加失敗 , 圖書管理系統(tǒng) ,JOptionPane.WARNING_MESSAGE);class Pmain extends Panel / 窗口面板布局Label l1 = new Label( 圖書管理系統(tǒng), Label.CENTER);Label l2 = new Labe
15、l( 計算機學院 , Label.RIGHT);Label l3 = new Label(, Label.RIGHT);Label l4 = new Label( 作者: JHL, Label.RIGHT);Pmain() setLayout(null);setBackground(Color.white);add(l1);add(l2);add(l3);add(l4);l1.setBounds(10, 60, 320, 40);l2.setBounds(240, 120, 80, 22);l3.setBounds(240, 142, 80, 22);l4.setBounds(240, 164
16、, 80, 22);setSize(340, 250);setVisible(true);validate();class Pchaxun extends Panel implements ActionListener / 圖書查詢 Choice cchaxun;TextField tchaxun;Button btnchaxun;TextArea tachaxun;Pchaxun() setLayout(null);cchaxun = new Choice(); /創(chuàng)建下拉菜單cchaxun.add( 書名 );cchaxun.add( 作者 );cchaxun.add( 出版社 );tch
17、axun = new TextField();btnchaxun = new Button(查詢 ); /創(chuàng)建按鈕tachaxun = new TextArea(); /創(chuàng)建多行文本框add(cchaxun);add(tchaxun);add(btnchaxun);add(tachaxun);tchaxun.setText();cchaxun.setBounds(10, 10, 65, 20);tchaxun.setBounds(85, 10, 180, 20);btnchaxun.setBounds(275, 10, 40, 20);tachaxun.setBounds(10, 40, 30
18、5, 145);cchaxun.select(0); /下拉菜單的初始選項setSize(340, 250); /設置窗口大小setBackground(Color.white);setVisible(true);btnchaxun.addActionListener(this);validate();public void actionPerformed(ActionEvent e) int i = cchaxun.getSelectedIndex();String s = tchaxun.getText();if (s.equals()JOptionPane.showMessageDial
19、og(this,查詢內(nèi)容不能為空 , 查詢系統(tǒng) ,JOptionPane.WARNING_MESSAGE);else Connection con;Statement sql;ResultSet rs;try Class.forName(oracle.jdbc.driver.OracleDriver); /加載 JDBC驅(qū)動 catch (ClassNotFoundException ee) System.out.println( + ee);try con = DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl,s
20、a, orcl);/連接數(shù)據(jù)庫sql = con.createStatement();if (i = 0) /根據(jù)下拉菜單的選項執(zhí)行不同的SQL語句rs = sql.executeQuery(select * from book where bookName =+ + s + );else if (i = 1)rs = sql.executeQuery(select * from book where author =+ + s + );elsers = sql.executeQuery(select * from book where publisher =+ + s + );tachaxu
21、n.setText();String panduan = false;while (rs.next() panduan = true;tachaxun.append( 書名 : + rs.getString(1) + n);tachaxun.append( 作者 : + rs.getString(2) + n);tachaxun.append( 出版社 : + rs.getString(3) + n);tachaxun.append( 出版日期 : + rs.getString(4) + n);tachaxun.append( 評論 : + rs.getString(5) + n); / 顯示
22、查詢到的圖書信息rs = sql.executeQuery(select count(*) from book); / 統(tǒng)計所有圖書數(shù) while (rs.next() tachaxun.append( 圖書館暫有 + rs.getString(1) + 本圖書 ); / 顯示所有圖書數(shù)量信息con.close(); /關閉數(shù)據(jù)庫if (panduan.equals(false)JOptionPane.showMessageDialog(this, 沒有該記錄 , 查詢系統(tǒng) ,JOptionPane.WARNING_MESSAGE); catch (SQLException eee) Syst
23、em.out.println(eee);class Pshanchu extends Panel implements ActionListener / 刪除功能模塊 Choice cshanchu;TextField tshanchu;Button btnshanchu;Label l1 = new Label(, Label.CENTER);Label l2 = new Label( 計算機學院 , Label.RIGHT);Label l3 = new Label(, Label.RIGHT);Label l4 = new Label( 作者: ZCS, Label.RIGHT);Psh
24、anchu() setLayout(null);cshanchu = new Choice(); /創(chuàng)建下拉菜單cshanchu.add( 書名 );tshanchu = new TextField();btnshanchu = new Button( 刪除 ); /創(chuàng)建按鈕add(cshanchu);add(tshanchu);add(btnshanchu);add(l1);add(l2);add(l3);add(l4); /添加標簽、按鈕等到窗口面板tshanchu.setText();cshanchu.setBounds(10, 10, 65, 20);tshanchu.setBound
25、s(85, 10, 180, 20);btnshanchu.setBounds(275, 10, 40, 20);l1.setBounds(10, 40, 300, 40);l2.setBounds(240, 130, 80, 22);l3.setBounds(240, 152, 80, 22);l4.setBounds(240, 174, 80, 22);cshanchu.select(0);setSize(340, 250); /設置窗口大小setBackground(Color.white);setVisible(true);btnshanchu.addActionListener(th
26、is);validate();public void actionPerformed(ActionEvent e) String s = tshanchu.getText();if (s.equals()JOptionPane.showMessageDialog(this, 請輸入要刪除的圖書 , 刪除功能 , JOptionPane.WARNING_MESSAGE);else Connection con;Statement sql;ResultSet rs;try Class.forName(oracle.jdbc.driver.OracleDriver); catch (ClassNot
27、FoundException ee) System.out.println( + ee);try con = DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl,sa, orcl);sql = con.createStatement();rs = sql.executeQuery(select * from book where bookName =+ + s + );if (!rs.next()JOptionPane.showMessageDialog(this, 沒有該圖書 , 刪除功能 , JOptionPan
28、e.WARNING_MESSAGE);else int n = JOptionPane.showConfirmDialog(this, 確認刪除嗎 ?, 刪除功能 , JOptionPane.YES_NO_OPTION); if (n = JOptionPane.YES_OPTION) sql.executeUpdate(delete from book where bookName =+ + s + );JOptionPane.showMessageDialog(this, 刪除成功 , 刪除功能 ,JOptionPane.INFORMATION_MESSAGE);tshanchu.setText(); elsetshanchu.setText();con.close(); catch (SQLException eee) System.out.println(ee
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 新版試用期勞動合同模板合同
- 土地承包合同法律文本示例
- 廠家設備租賃合同樣本集錦
- 項目合作人才服務合同
- 茶葉購銷合同模板
- 新產(chǎn)品開發(fā)項目合同協(xié)議書范本
- 保密合同-工作手機保管細則
- 度設備采購借款合同模板
- 倉儲用房租賃合同參考樣本
- 度醫(yī)療服務采購合同
- 產(chǎn)品不良品(PPM)統(tǒng)計表格模板
- 新教科版四年級下冊科學全冊重點題型練習課件(含答案)
- 五星傳變 廖金精
- 亮化工程投標書
- 公園棧道棧橋施工方案
- 不規(guī)則抗體篩查與鑒定
- 中國銀行海爾多聯(lián)機方案書
- 涂布機初級操作技術與維修培訓課件
- GB/T 8417-2003燈光信號顏色
- GB/T 7984-2001輸送帶具有橡膠或塑料覆蓋層的普通用途織物芯輸送帶
- GB/T 7631.10-2013潤滑劑、工業(yè)用油和有關產(chǎn)品(L類)的分類第10部分:T組(渦輪機)
評論
0/150
提交評論