![個人圖書管理系統(tǒng)_第1頁](http://file4.renrendoc.com/view/b55ca06d8084f49f8309240249084967/b55ca06d8084f49f83092402490849671.gif)
![個人圖書管理系統(tǒng)_第2頁](http://file4.renrendoc.com/view/b55ca06d8084f49f8309240249084967/b55ca06d8084f49f83092402490849672.gif)
![個人圖書管理系統(tǒng)_第3頁](http://file4.renrendoc.com/view/b55ca06d8084f49f8309240249084967/b55ca06d8084f49f83092402490849673.gif)
![個人圖書管理系統(tǒng)_第4頁](http://file4.renrendoc.com/view/b55ca06d8084f49f8309240249084967/b55ca06d8084f49f83092402490849674.gif)
![個人圖書管理系統(tǒng)_第5頁](http://file4.renrendoc.com/view/b55ca06d8084f49f8309240249084967/b55ca06d8084f49f83092402490849675.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
個人圖書管理系統(tǒng)java代碼publicclassBook{ privateStringname;//書名 privateStringfenlei;//分類 privateStringbuyTime;//購置時間 privatedoublevalue;//價格 privateStringjianjie;//簡介publicBook(){ name=""; fenlei=""; buyTime =""; value=0; jianjie =""; } publicBook(Stringn,Stringf,Stringb,doublev,Stringj){ name=n; fenlei=f; buyTime =b; value=v; jianjie =j; }publicvoidsetName(Stringn){ name=n;} publicvoidsetFenlei(Stringf){ fenlei=f;} publicvoidsetBuyTime(Stringb){ buyTime =b;} publicvoidsetValue(doublev){ value=v;} publicvoidsetJianjie(Stringj){ jianjie =j; } publicStringgetName(){ returnname;} publicStringgetFenlei(){ returnfenlei;}publicStringgetBuyTime(){ returnbuyTime;}publicdoublegetValue(){ returnvalue;}publicStringgetJianjie(){ returnjianjie;} }/***@(#)MyBookSystem.java*@author*@version1.002023/3/6*/importjava.awt.*;importjavax.swing.*;import.*;import;import;importjava.util.*;import;import;import;import;importjava.io.*;publicclassMyBookSystemimplementsActionListener,TreeSelectionListener{ JFrameframe; JPanelpanel1; JPanelpanel2; JMenuBarmenubar;//菜單欄 JMenufile; JMenusort;//排序 JMenucaozuo;//操作 JMenuItemcancel; JMenuItemsort1;//按價格排序 JMenuItemsort2;//按字母排序 JMenuItemaddJMenuItem; JMenuItemdeleteJMenuItem; JMenuItemfindJMenuItem; JTreejTree=null;JTextAreatextArea;JScrollPanescrollPane;JButtonadd;JButtondelete;JButtonfind;DefaultTreeModeltreeModel=null;privateFilefileBook;privateArrayListarrayList;String[]str={"經(jīng)典","言情","歷史","科技","人文","健康","生活","教材"};DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("我旳書籍");/***Createsanewinstanceof<code>MyBookSystem</code>.*/publicMyBookSystem(){ frame=newJFrame("我旳書管理系統(tǒng)"); frame.setSize(500,400); frame.setLayout(newBorderLayout()); //設置panel1 panel1=newJPanel(); panel1.setBackground(Color.gray); jTree=newJTree(getTree()); treeModel=(DefaultTreeModel)jTree.getModel();// jTree.addTreeSelectionListener(this); panel1.add(jTree); //設置panel2 panel2=newJPanel(); panel2.setLayout(null); textArea=newJTextArea();scrollPane=newJScrollPane(textArea); add=newJButton("增長"); delete=newJButton("刪除"); find=newJButton("查找"); add.addActionListener(this); delete.addActionListener(this); find.addActionListener(this); // textArea.setBounds(0,0,450,260); scrollPane.setBounds(0,0,450,260); add.setBounds(15,280,100,40); delete.setBounds(145,280,100,40); find.setBounds(270,280,100,40);// panel2.add(textArea); panel2.add(scrollPane); panel2.add(add); panel2.add(delete); panel2.add(find); //設置菜單欄 menubar=newJMenuBar(); file=newJMenu("文獻"); sort=newJMenu("排序"); caozuo=newJMenu("操作");addJMenuItem=newJMenuItem("增長");deleteJMenuItem=newJMenuItem("刪除");findJMenuItem=newJMenuItem("查找"); cancel=newJMenuItem("退出");sort1=newJMenuItem("按價格"); sort2=newJMenuItem("按名字"); menubar.add(file); menubar.add(sort); menubar.add(caozuo); file.add(cancel); caozuo.add(addJMenuItem); caozuo.add(deleteJMenuItem); caozuo.add(findJMenuItem); sort.add(sort1); sort.add(sort2); addJMenuItem.addActionListener(this); deleteJMenuItem.addActionListener(this); findJMenuItem.addActionListener(this); cancel.addActionListener(this); sort1.addActionListener(this); sort2.addActionListener(this); frame.addWindowListener(newWindowAdapter(){ publicvoidwindowClosing(WindowEventwe){ System.exit(0); }}); frame.add("North",menubar); frame.add("West",panel1); frame.add("Center",panel2); frame.setVisible(true); fileBook=newFile("圖書.dat"); arrayList=newArrayList(); readFile();}privateDefaultMutableTreeNodegetTree(){for(inti=0;i<str.length;i++) root.add(newDefaultMutableTreeNode(str[i]));returnroot;}privatevoidreadFile(){ try{ ObjectInputStreamois=newObjectInputStream(newFileInputStream(fileBook)); arrayList=(ArrayList)ois.readObject(); ois.close(); }catch(Exceptione){}} privatevoidwriteFile(Bookbook){//寫文獻 try{ ObjectOutputStreamoos=newObjectOutputStream(newFileOutputStream("圖書.dat")); arrayList.add(book); oos.writeObject(arrayList); oos.close(); }catch(Exceptione){}}//實現(xiàn)ActionListener措施publicvoidactionPerformed(ActionEventae){ intlen=arrayList.size(); if(ae.getSource()==add||ae.getSource()==addJMenuItem){ AddDialogadd=newAddDialog(this.frame,true); add.show(); }elseif(ae.getSource()==find||ae.getSource()==findJMenuItem){ if(len==0){ JOptionPane.showMessageDialog(frame,"我旳書籍里沒書!?。?); return;} find();}elseif(ae.getSource()==delete||ae.getSource()==deleteJMenuItem){ if(len==0){ JOptionPane.showMessageDialog(frame,"我旳書籍里沒書?。?!"); return;} delete(); }elseif(ae.getSource()==sort1){ sortValue();}elseif(ae.getSource()==sort2){ }elseif(ae.getSource()==cancel){ System.exit(0); }}//實現(xiàn)TreeSelectionListener措施publicvoidvalueChanged(TreeSelectionEvente){DefaultMutableTreeNodedefaultNode=(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();if(defaultNode!=null){ Stringname=defaultNode.getUserObject().toString(); intlen=arrayList.size(); inti=0; while(i<len){ Booktemp=(Book)arrayList.get(i); if(temp.getName().equals(name)){ textArea.setText("\n書名:"+temp.getName()+"\n類別:" +temp.getFenlei()+"\n購置時間:"+temp.getBuyTime() +"\n單價:"+temp.getValue()+"\n簡介:" +temp.getJianjie()); return; } i++; }}}//刪除書publicvoiddelete(){Stringname="";try{ name=JOptionPane.showInputDialog(frame,"請輸入書名:","不能為空"); }catch(Exceptione){("hejhtrjy6r");}if(name.equalsIgnoreCase("")){return;}intlen=arrayList.size();inti=0;Booktemp=newBook();while(i<len){ temp=(Book)arrayList.get(i); if(name.equalsIgnoreCase(temp.getName())){ arrayList.remove(i); break; } i++;}if(i==len){ JOptionPane.showMessageDialog(frame,"不存在該書?。?!"); return; }else{ deleteJTreeNode(temp.getName(),temp.getFenlei()); textArea.setText("該書:\n"+"書名:"+temp.getName()+"\n類別:"+temp.getFenlei()+"\n購置時間:" +temp.getBuyTime()+"\n單價:"+temp.getValue()+"\n簡介:"+temp.getJianjie()+"刪除成功!!"); } }privatevoiddeleteJTreeNode(Stringname,Stringfenlei){ DefaultMutableTreeNodeparent=root.getNextNode(); while(parent!=null&&!parent.getUserObject().equals(fenlei)){ parent=parent.getNextSibling();//獲得兄弟節(jié)點 }DefaultMutableTreeNodechild=parent.getFirstLeaf();while(child!=null&&!child.getUserObject().equals(name)){ child=child.getNextSibling();//獲得兄弟節(jié)點} treeModel.removeNodeFromParent(child); }//找書publicvoidfind(){Stringname="";try{ name=JOptionPane.showInputDialog(frame,"請輸入書名:","不能為空"); }catch(Exceptione){("g43h35h54h4j"+name);return;}if(name.equalsIgnoreCase("")){return;}intlen=arrayList.size();inti=0;Booktemp=newBook();while(i<len){ temp=(Book)arrayList.get(i); if(name.equalsIgnoreCase(temp.getName())){ break; } i++;}if(i==len){ textArea.setText("\n\n沒有該書!!"); return; }else{ textArea.setText("您要找旳書:\n"+"書名:"+temp.getName()+"\n類別:"+temp.getFenlei()+"\n購置時間:" +temp.getBuyTime()+"\n單價:"+temp.getValue()+"\n簡介:"+temp.getJianjie()); } }//排序publicvoidsortValue(){//按單價 intn=arrayList.size();inti,j,max;for(i=0;i<n-1;i++){ max=i; for(j=i+1;j<n;j++){ Books1=(Book)arrayList.get(j); Books2=(Book)arrayList.get(max); doublev1=s1.getValue(); doublev2=s2.getValue(); if(v1>v2)max=j; } if(max!=i){ Booktemp1=(Book)arrayList.get(i); Booktemp2=(Book)arrayList.get(max); arrayList.set(i,temp2); arrayList.set(max,temp1); } }printArrayList(); } // publicvoidsortName(){//按書名// } privatevoidprintArrayList(){ intn=arrayList.size(); inti=0; Stringstr=""; for(;i<n;i++){ Booktemp=(Book)arrayList.get(i); str+="第"+(i+1)+":\n"+"書名:"+temp.getName()+"\n類別:"+temp.getFenlei()+"\n購置時間:" +temp.getBuyTime()+"\n單價:"+temp.getValue()+"\n簡介:"+temp.getJianjie()+"\n\n"; }textArea.setText(str); }/****************內(nèi)部類增長對話框********************/classAddDialogextendsJDialogimplementsActionListener{ //創(chuàng)立組件 JFrameframe1;//主程序旳界面 JLabelisnamedLabel=newJLabel();//用來顯示名字與否存在 JLabelnameLabel=newJLabel("書名:"); JLabelflLabel=newJLabel("分類:"); JLabelbtLabel=newJLabel("購置日期:"); JLabelvaLabel=newJLabel("價格:"); JLabeljjLabel=newJLabel("簡介:"); JTextFieldnametf=newJTextField(); JTextFieldbttf=newJTextField(); JComboBoxflComboBox; JTextFieldvatf=newJTextField(); JTextAreajjta=newJTextArea(5,10); JButtonok=newJButton("確定"); JButtoncancel2=newJButton("取消"); publicAddDialog(JFrameparent,booleanmodal){ //設置對話框 super(parent,modal); frame1=parent; setTitle("增長圖書"); setSize(400,330); setLayout(null); flComboBox=newJComboBox(str); flComboBox.setEditable(true); //設置組件旳位置 nameLabel.setBounds(80,30,30,20); flLabel.setBounds(80,60,30,20); btLabel.setBounds(80,90,60,20); vaLabel.setBounds(80,120,30,20); jjLabel.setBounds(80,150,30,20); nametf.setBounds(150,30,180,20);flComboBox.setBounds(150,60,180,20); bttf.setBounds(150,90,180,20); vatf.setBounds(150,120,180,20); jjta.setBounds(150,150,180,90); ok.setBounds(100,255,65,30); cancel2.setBounds(200,255,65,30); //添加組件 add(nameLabel); add(flLabel); add(btLabel); add(vaLabel); add(jjLabel); add(nametf);add(flComboBox); add(bttf); add(vatf); add(jjta); add(ok); add(cancel2); //注冊監(jiān)聽 ok.addActionListener(this); cancel2.addActionListener(this); //添加關閉窗口監(jiān)聽器 addWindowListener(newWindowAdapter(){ publicvoidwindowClosing(WindowEventwe){ setVisible(false);; } }); } publicvoidactionPerformed(ActionEventae){if(ae.getSource()==ok){ addBook();}elseif(ae.getSource()==cancel2){ this.setVisible(false);} }publicvoidaddBook(){ readFile(); Stringname=nametf.getText(); if(name.equalsIgnoreCase("")){ JOptionPane.showMessageDialog(this,"書名不能為空??!"); return; } if(isHad(name)){ JOptionPane.showMessageDialog(this,"該書已存在!!"); return; } Stringfenlei=flComboBox.getSelectedItem().toString(); doublevalue=0; if(!vatf.getText().equalsIgnoreCase("")) try{ value=Double.parseDouble(vatf.getText()); }catch(Exceptione){} Bookbook=newBook(name,fenlei,bttf.getText(),value,jjta.getText()); writeFile(book); textArea.setText("該書:\n"+"書名:"+name+"\n類別:"+fenlei+"\n購置時間:" +bttf.getText()+"\n單價:"+value+"\n簡介:"+jjta.getText()+"\n添加成功。");
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 現(xiàn)代物流信息系統(tǒng)建設中的標準化問題
- 掛繩高空作業(yè)施工方案
- 拆除臨時用電施工方案
- 生態(tài)文明教育在校園的實踐與推廣
- 現(xiàn)代企業(yè)綜合管理能力提升及領導力培訓方案研究報告
- 國慶節(jié)營銷活動方案模板
- 2023三年級語文上冊 第一單元 習作:猜猜他是誰說課稿 新人教版
- Unit 2 AnimaIs Lesson 1 Enjoy the story(說課稿)-2024-2025學年北師大版(三起)英語五年級上冊
- 2024秋八年級物理上冊 第1章 機械運動 第2節(jié) 運動的描述說課稿2(新版)新人教版
- 2025仿石漆施工合同
- 中日勞務合同范本
- 白宮-人工智能行業(yè):美國人工智能權利法案藍圖(英譯中)
- 營口市大學生??紝U锌荚囌骖}2022
- 典范英語8-15Here comes trouble原文翻譯
- 六安市葉集化工園區(qū)污水處理廠及配套管網(wǎng)一期工程環(huán)境影響報告書
- 運動技能學習與控制課件第一章運動技能學習與控制概述
- 固體廢棄物檢查記錄
- 工程設計費取費標準
- 2023年遼寧鐵道職業(yè)技術學院高職單招(數(shù)學)試題庫含答案解析
- CAPP教學講解課件
- 自然環(huán)境的服務功能課件 高中地理人教版(2019)選擇性必修3
評論
0/150
提交評論