個(gè)人圖書(shū)管理系統(tǒng)_第1頁(yè)
個(gè)人圖書(shū)管理系統(tǒng)_第2頁(yè)
個(gè)人圖書(shū)管理系統(tǒng)_第3頁(yè)
個(gè)人圖書(shū)管理系統(tǒng)_第4頁(yè)
個(gè)人圖書(shū)管理系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩21頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

個(gè)人圖書(shū)管理系統(tǒng)java代碼publicclassBook{ privateStringname;//書(shū)名 privateStringfenlei;//分類 privateStringbuyTime;//購(gòu)置時(shí)間 privatedoublevalue;//價(jià)格 privateStringjianjie;//簡(jiǎn)介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;//按價(jià)格排序 JMenuItemsort2;//按字母排序 JMenuItemaddJMenuItem; JMenuItemdeleteJMenuItem; JMenuItemfindJMenuItem; JTreejTree=null;JTextAreatextArea;JScrollPanescrollPane;JButtonadd;JButtondelete;JButtonfind;DefaultTreeModeltreeModel=null;privateFilefileBook;privateArrayListarrayList;String[]str={"經(jīng)典","言情","歷史","科技","人文","健康","生活","教材"};DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("我旳書(shū)籍");/***Createsanewinstanceof<code>MyBookSystem</code>.*/publicMyBookSystem(){ frame=newJFrame("我旳書(shū)管理系統(tǒng)"); frame.setSize(500,400); frame.setLayout(newBorderLayout()); //設(shè)置panel1 panel1=newJPanel(); panel1.setBackground(Color.gray); jTree=newJTree(getTree()); treeModel=(DefaultTreeModel)jTree.getModel();// jTree.addTreeSelectionListener(this); panel1.add(jTree); //設(shè)置panel2 panel2=newJPanel(); panel2.setLayout(null); textArea=newJTextArea();scrollPane=newJScrollPane(textArea); add=newJButton("增長(zhǎng)"); 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); //設(shè)置菜單欄 menubar=newJMenuBar(); file=newJMenu("文獻(xiàn)"); sort=newJMenu("排序"); caozuo=newJMenu("操作");addJMenuItem=newJMenuItem("增長(zhǎng)");deleteJMenuItem=newJMenuItem("刪除");findJMenuItem=newJMenuItem("查找"); cancel=newJMenuItem("退出");sort1=newJMenuItem("按價(jià)格"); 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("圖書(shū).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){//寫(xiě)文獻(xiàn) try{ ObjectOutputStreamoos=newObjectOutputStream(newFileOutputStream("圖書(shū).dat")); arrayList.add(book); oos.writeObject(arrayList); oos.close(); }catch(Exceptione){}}//實(shí)現(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,"我旳書(shū)籍里沒(méi)書(shū)!??!"); return;} find();}elseif(ae.getSource()==delete||ae.getSource()==deleteJMenuItem){ if(len==0){ JOptionPane.showMessageDialog(frame,"我旳書(shū)籍里沒(méi)書(shū)!??!"); return;} delete(); }elseif(ae.getSource()==sort1){ sortValue();}elseif(ae.getSource()==sort2){ }elseif(ae.getSource()==cancel){ System.exit(0); }}//實(shí)現(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書(shū)名:"+temp.getName()+"\n類別:" +temp.getFenlei()+"\n購(gòu)置時(shí)間:"+temp.getBuyTime() +"\n單價(jià):"+temp.getValue()+"\n簡(jiǎn)介:" +temp.getJianjie()); return; } i++; }}}//刪除書(shū)publicvoiddelete(){Stringname="";try{ name=JOptionPane.showInputDialog(frame,"請(qǐng)輸入書(shū)名:","不能為空"); }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,"不存在該書(shū)?。?!"); return; }else{ deleteJTreeNode(temp.getName(),temp.getFenlei()); textArea.setText("該書(shū):\n"+"書(shū)名:"+temp.getName()+"\n類別:"+temp.getFenlei()+"\n購(gòu)置時(shí)間:" +temp.getBuyTime()+"\n單價(jià):"+temp.getValue()+"\n簡(jiǎn)介:"+temp.getJianjie()+"刪除成功!!"); } }privatevoiddeleteJTreeNode(Stringname,Stringfenlei){ DefaultMutableTreeNodeparent=root.getNextNode(); while(parent!=null&&!parent.getUserObject().equals(fenlei)){ parent=parent.getNextSibling();//獲得兄弟節(jié)點(diǎn) }DefaultMutableTreeNodechild=parent.getFirstLeaf();while(child!=null&&!child.getUserObject().equals(name)){ child=child.getNextSibling();//獲得兄弟節(jié)點(diǎn)} treeModel.removeNodeFromParent(child); }//找書(shū)publicvoidfind(){Stringname="";try{ name=JOptionPane.showInputDialog(frame,"請(qǐng)輸入書(shū)名:","不能為空"); }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沒(méi)有該書(shū)!!"); return; }else{ textArea.setText("您要找旳書(shū):\n"+"書(shū)名:"+temp.getName()+"\n類別:"+temp.getFenlei()+"\n購(gòu)置時(shí)間:" +temp.getBuyTime()+"\n單價(jià):"+temp.getValue()+"\n簡(jiǎn)介:"+temp.getJianjie()); } }//排序publicvoidsortValue(){//按單價(jià) 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(){//按書(shū)名// } privatevoidprintArrayList(){ intn=arrayList.size(); inti=0; Stringstr=""; for(;i<n;i++){ Booktemp=(Book)arrayList.get(i); str+="第"+(i+1)+":\n"+"書(shū)名:"+temp.getName()+"\n類別:"+temp.getFenlei()+"\n購(gòu)置時(shí)間:" +temp.getBuyTime()+"\n單價(jià):"+temp.getValue()+"\n簡(jiǎn)介:"+temp.getJianjie()+"\n\n"; }textArea.setText(str); }/****************內(nèi)部類增長(zhǎng)對(duì)話框********************/classAddDialogextendsJDialogimplementsActionListener{ //創(chuàng)立組件 JFrameframe1;//主程序旳界面 JLabelisnamedLabel=newJLabel();//用來(lái)顯示名字與否存在 JLabelnameLabel=newJLabel("書(shū)名:"); JLabelflLabel=newJLabel("分類:"); JLabelbtLabel=newJLabel("購(gòu)置日期:"); JLabelvaLabel=newJLabel("價(jià)格:"); JLabeljjLabel=newJLabel("簡(jiǎn)介:"); JTextFieldnametf=newJTextField(); JTextFieldbttf=newJTextField(); JComboBoxflComboBox; JTextFieldvatf=newJTextField(); JTextAreajjta=newJTextArea(5,10); JButtonok=newJButton("確定"); JButtoncancel2=newJButton("取消"); publicAddDialog(JFrameparent,booleanmodal){ //設(shè)置對(duì)話框 super(parent,modal); frame1=parent; setTitle("增長(zhǎng)圖書(shū)"); setSize(400,330); setLayout(null); flComboBox=newJComboBox(str); flComboBox.setEditable(true); //設(shè)置組件旳位置 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); //注冊(cè)監(jiān)聽(tīng) ok.addActionListener(this); cancel2.addActionListener(this); //添加關(guān)閉窗口監(jiān)聽(tīng)器 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,"書(shū)名不能為空??!"); return; } if(isHad(name)){ JOptionPane.showMessageDialog(this,"該書(shū)已存在!!"); 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("該書(shū):\n"+"書(shū)名:"+name+"\n類別:"+fenlei+"\n購(gòu)置時(shí)間:" +bttf.getText()+"\n單價(jià):"+value+"\n簡(jiǎn)介:"+jjta.getText()+"\n添加成功。");

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論