




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、wordimport 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(); /
2、建立菜單欄Menu mfile = new Menu("功能"); / 建立“功能菜單組Menu mhelp = new Menu("幫助"); / 建立“幫助菜單組MenuItem mdenglu = new MenuItem("登陸");MenuItem mchaxun = new MenuItem("查詢");MenuItem mtianjia = new MenuItem("添加");MenuItem mshanchu = new MenuItem("刪除");Men
3、uItem mexit = new MenuItem("退出");MenuItem mhelpp = new MenuItem("關(guān)于");Denglu pdenglu=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(
4、mdenglu);mfile.add(mtianjia);mfile.add(mchaxun);mfile.add(mshanchu);mfile.add(mexit);mhelp.add(mhelpp);daohang.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);se
5、tResizable(false);setVisible(true);mexit.addActionListener(this);mdenglu.addActionListener(this);mtianjia.addActionListener(this);mchaxun.addActionListener(this);mshanchu.addActionListener(this);mhelpp.addActionListener(this);validate(); / 窗口事件監(jiān)聽public void actionPerformed(ActionEvent e) if (e.getSo
6、urce() = mexit)System.exit(0);if(e.getSource()=mdenglu)removeAll();add(pdenglu);validate();if (e.getSource() = mtianjia) removeAll();add(ptianjia);validate(); / 圖書添加功能if (e.getSource() = mchaxun) removeAll();add(pchaxun);validate(); / 圖書查詢功能if (e.getSource() = mshanchu) removeAll();add(pshanchu);val
7、idate(); / 圖書刪除功能if (e.getSource() = mhelpp) JOptionPane.showMessageDialog(this, "歡迎使用圖書管理系統(tǒng)", "關(guān)于本系統(tǒng)",JOptionPane.INFORMATION_MESSAGE); / 各功能菜單事件監(jiān)聽/class Ptianjia extends Panel implements ActionListener TextField tname, tauthor, tpublish, tdate, tcomment;Label lname, lauthor, lp
8、ublish, ldate, lcomment;Button btn;Ptianjia() setLayout(null);btn = new Button("添加"); / 創(chuàng)立“添加按鈕tname = new TextField();tauthor = new TextField();tpublish = new TextField();tdate = new TextField();tcomment = new TextField(); / 創(chuàng)立5個文本框lname = new Label("書名");lauthor = new Label(&qu
9、ot;作者");lpublish = new Label("出版社");ldate = new Label("出版日期");lcomment = new Label("評論");add(lname);add(tname);add(lauthor);add(tauthor);add(lpublish);add(tpublish);add(ldate);add(tdate);add(lcomment);add(tcomment);add(btn); / 添加“按鈕到窗口面板上lname.setBounds(10, 10, 70,
10、 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.setBounds(10, 100, 70, 25);tdate.setBounds(90, 100, 220, 25);lcomment.setBounds(10, 130, 70, 25);tcomment.setBounds(
11、90, 130, 220, 25);btn.setBounds(130, 160, 70, 25); / 設(shè)置按鈕位置btn.addActionListener(this); / 設(shè)置按鈕監(jiān)聽setSize(340, 250); / 設(shè)置窗口大小setBackground(Color.white); / 設(shè)置窗口背景顏色setVisible(true);validate(); public void actionPerformed(ActionEvent e) String sname = tname.getText();String sauthor = tauthor.getText();S
12、tring spublish = tpublish.getText();String sdate = tdate.getText();String scomment = tcomment.getText();String insertstr = "insert into book values" + "(" + "'" + sname + "'"+ "," + "'" + sauthor + "'" + ",&qu
13、ot; + "'" + spublish + "'" + ","+ "'" + sdate + "'" + "," + "'" + scomment + "'" + ")" / SQL語句Connection con;Statement sta;ResultSet rs;try Class.forName("oracle.jdbc.driver.OracleD
14、river"); / 加載JDBC驅(qū)動 catch (ClassNotFoundException ee) System.out.println("" + ee);try con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "sa", "orcl"); / 連接數(shù)據(jù)庫sta = con.createStatement();sta.executeUpdate(insertstr); / 執(zhí)行SQL語句con.cl
15、ose(); / 關(guān)閉數(shù)據(jù)庫tname.setText("");tauthor.setText("");tpublish.setText("");tdate.setText("");tcomment.setText(""); / 重新初始化文本框內(nèi)容JOptionPane.showMessageDialog(this, "添加成功", "圖書管理系統(tǒng)",JOptionPane.INFORMATION_MESSAGE); catch (SQLExceptio
16、n eee) System.out.println("" + eee);tname.setText("");tauthor.setText("");tpublish.setText("");tdate.setText("");tcomment.setText("");JOptionPane.showMessageDialog(this, "添加失敗", "圖書管理系統(tǒng)",JOptionPane.WARNING_MESSAGE);clas
17、s Pmain extends Panel / 窗口面板布局Label l1 = new Label("圖書管理系統(tǒng)", Label.CENTER);Label l2 = new Label("計算機學(xué)院", Label.RIGHT);Label l3 = new Label("", Label.RIGHT);Label l4 = new Label(" JHL", Label.RIGHT);Pmain() setLayout(null);setBackground(Color.white);add(l1);add
18、(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, 80, 22);setSize(340, 250);setVisible(true);validate();class Pchaxun extends Panel implements ActionListener / 圖書查詢Choice cchaxun;TextField tchaxun;Button btnchaxun;
19、TextArea tachaxun;Pchaxun() setLayout(null);cchaxun = new Choice(); / 創(chuàng)立下拉菜單cchaxun.add("書名");cchaxun.add("作者");cchaxun.add("出版社");tchaxun = new TextField();btnchaxun = new Button("查詢"); / 創(chuàng)立按鈕tachaxun = new TextArea(); / 創(chuàng)立多行文本框add(cchaxun);add(tchaxun);add(b
20、tnchaxun);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, 305, 145);cchaxun.select(0); / 下拉菜單的初始選項setSize(340, 250); / 設(shè)置窗口大小setBackground(Color.white);setVisible(true);bt
21、nchaxun.addActionListener(this);validate();public void actionPerformed(ActionEvent e) int i = cchaxun.getSelectedIndex();String s = tchaxun.getText();if (s.equals("")JOptionPane.showMessageDialog(this, "查詢內(nèi)容不能為 空", "查詢系統(tǒng)",JOptionPane.WARNING_MESSAGE);else Connection con
22、;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", "sa", "orcl");/ 連
23、接數(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 + "'&qu
24、ot;);elsers = sql.executeQuery("select * from book where publisher ="+ "'" + s + "'");tachaxun.setText("");String panduan = "false"while (rs.next() panduan = "true"tachaxun.append("書名:" + rs.getString(1) + "n");t
25、achaxun.append("作者:" + rs.getString(2) + "n");tachaxun.append("出版社:" + rs.getString(3) + "n");tachaxun.append("出版日期:" + rs.getString(4) + "n");tachaxun.append("評論:" + rs.getString(5) + "n"); / 顯示查詢到的圖書信息rs = sql.executeQ
26、uery("select count(*) from book"); / 統(tǒng)計所有圖書數(shù)while (rs.next() tachaxun.append("圖書館暫有" + rs.getString(1) + "本圖書"); / 顯示所有圖書數(shù)量信息con.close(); / 關(guān)閉數(shù)據(jù)庫if (panduan.equals("false")JOptionPane.showMessageDialog(this, "沒有該記錄", "查詢系統(tǒng)",JOptionPane.WARN
27、ING_MESSAGE); catch (SQLException eee) System.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("計算機學(xué)院", Label.RIGHT);Label l3 = new Labe
28、l("", Label.RIGHT);Label l4 = new Label(" ZCS", Label.RIGHT);Pshanchu() 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(
29、l2);add(l3);add(l4); / 添加標(biāo)簽、按鈕等到窗口面板tshanchu.setText("");cshanchu.setBounds(10, 10, 65, 20);tshanchu.setBounds(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);c
30、shanchu.select(0);setSize(340, 250); / 設(shè)置窗口大小setBackground(Color.white);setVisible(true);btnshanchu.addActionListener(this);validate();public void actionPerformed(ActionEvent e) String s = tshanchu.getText();if (s.equals("")JOptionPane.showMessageDialog(this, "請輸入要刪除的圖書", "刪
31、除功能",JOptionPane.WARNING_MESSAGE);else Connection con;Statement sql;ResultSet rs;try Class.forName("oracle.jdbc.driver.OracleDriver"); catch (ClassNotFoundException ee) System.out.println("" + ee);try con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:or
32、cl", "sa", "orcl");sql = con.createStatement();rs = sql.executeQuery("select * from book where bookName ="+ "'" + s + "'");if (!rs.next()JOptionPane.showMessageDialog(this, "沒有該圖書", "刪除功能",JOptionPane.WARNING_MESSAGE)
33、;else int n = JOptionPane.showConfirmDialog(this, "確認(rèn)刪除嗎?","刪除功能", 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(); cat
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 勞動合同范本002
- 中標(biāo)人支付合同范本
- 割草合同范例
- 印章保管合同范本律師
- 發(fā)電機保養(yǎng)合同范本
- 合資做房子合同范例
- 到期不住合同范本
- 醫(yī)院工程材料采購合同范本
- 廠房阻力合同范本
- 人贅婿合同范本
- 個人應(yīng)聘簡歷電工
- 2025年上半年河南省高校畢業(yè)生“三支一扶”招募1100人易考易錯模擬試題(共500題)試卷后附參考答案
- 高血壓的用藥指導(dǎo)任務(wù)三高血壓的藥物治療講解
- 《馬云創(chuàng)業(yè)經(jīng)歷》課件
- 云南省大理白族自治州2024-2025學(xué)年八年級上學(xué)期1月期末考試英語試卷(無答案)
- 無人機行業(yè)市場分析指南
- 踇外翻病人護理查房
- 廣西河池市(2024年-2025年小學(xué)六年級語文)統(tǒng)編版專題練習(xí)(上學(xué)期)試卷及答案
- 施工安全管理培訓(xùn)資料
- 2024中考物理真題匯編:電與磁(含解析)
- 中建10t龍門吊安拆安全專項施工方案
評論
0/150
提交評論