簡(jiǎn)易圖書管理系統(tǒng)_第1頁(yè)
簡(jiǎn)易圖書管理系統(tǒng)_第2頁(yè)
簡(jiǎn)易圖書管理系統(tǒng)_第3頁(yè)
簡(jiǎn)易圖書管理系統(tǒng)_第4頁(yè)
簡(jiǎn)易圖書管理系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

本程序以java為設(shè)計(jì)語言,能夠?qū)崿F(xiàn)一個(gè)簡(jiǎn)單的圖書管理系統(tǒng),可以實(shí)現(xiàn)簡(jiǎn)單的增加圖書,查詢圖書,刪除圖書的功能,其中用到數(shù)據(jù)庫(kù)的連接,窗體的布局管理。本程序有以下幾個(gè)功能函數(shù)組成所有模塊都在名為bookmanager的包中1:主函數(shù)mainframe.java2:增加模塊adddialog。java3:查詢模塊searchdialog.java4:查詢結(jié)果模塊searchresult.java精品文檔放心下載5:書本類book。java6:數(shù)據(jù)庫(kù)連接類dbcon。java主界面添加模塊查詢模塊輸出模塊源程序如下1.mainframe。javapackagebookmanager;importjavax。swing。*;importjavax.swing。table.DefaultTableModel;謝謝閱讀importjava。awt.*;importjava.awt.event.*;importjava。sql。Connection;謝謝閱讀importjava。sql。PreparedStatement;感謝閱讀importjava。sql。ResultSet;謝謝閱讀importjava。sql.SQLException;感謝閱讀importjava。util.LinkedList;謝謝閱讀publicclassmainframeextendsJFrameimplementsActionListener{privateJToolBartb;精品文檔放心下載String[]btntitle={"增加”,”查詢","刪除”,"退出”};感謝閱讀String[]tabeltitle={”圖書編號(hào)",”書名",”定價(jià)”,"出版社”};JButtonbtn[]=newJButton[4];JTabletable;精品文檔放心下載DefaultTableModelmodel;publicmainframe(){super(”圖書管理系統(tǒng)");//初始化各個(gè)按鈕tb=newJToolBar("工具欄”);for(inti=0;i<btntitle.length;i++){謝謝閱讀btn[i]=newJButton(btntitle[i]);精品文檔放心下載btn[i]。addActionListener(this);謝謝閱讀tb。add(btn[i]);}//創(chuàng)建表模型model=newDefaultTableModel(tabeltitle,10);table=newJTable(model);謝謝閱讀//設(shè)定單元格的高度table。setRowHeight(25);add(tb,BorderLayout.NORTH);感謝閱讀add(newJScrollPane(table),BorderLayout.CENTER);感謝閱讀setSize(900,600);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);精品文檔放心下載setLocation(100,30);init();}publicvoidactionPerformed(ActionEvente){感謝閱讀mainframem=newmainframe();謝謝閱讀Objecto=e.getSource();{if(o==btn[0]){adddialogad=newadddialog(m,25,25);謝謝閱讀init();}if(o==btn[1]){searchdialogsd=newsearchdialog(m,25,25);sd.dialog.setVisible(true);init();謝謝閱讀}if(o==btn[2]){intresult=JOptionPane。showConfirmDialog(null,”確實(shí)要?jiǎng)h除該條圖書信息精品文檔放心下載嗎?”,"確認(rèn)",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);謝謝閱讀if(result==0){Connectioncon=dbcon。getconnectin();感謝閱讀Objectob=model.getValueAt(table。getSelectedRow(),0);dbcon.delete(con,ob);精品文檔放心下載init();}else{return;}}if(o==btn[3]){System。exit(0);}}}publicvoidinit(){Connectioncon=dbcon。getconnectin();感謝閱讀LinkedListlist=null;try{PreparedStatementstmt=con.prepareStatement("select*from感謝閱讀book”);ResultSetrs=stmt。executeQuery();感謝閱讀list=newLinkedList();while(rs.next()){Stringid=rs.getString(1);謝謝閱讀Stringname=rs.getString(2);感謝閱讀Stringprice=rs.getString(3);精品文檔放心下載Stringpublish=rs。getString(4);精品文檔放心下載bookb=newbook(id,name,F(xiàn)loat.valueOf(price),publish);精品文檔放心下載list.add(b);}model.setRowCount(0);for(inti=0;i〈list。size();i++){精品文檔放心下載bookb=(book)list.get(i);Object[]str={b。getid(),b.getname(),b。getprice(),b。謝謝閱讀getpublish()};model.addRow(str);}}catch(SQLExceptione){謝謝閱讀TODOAuto—generatedcatchblock謝謝閱讀e.printStackTrace();}}publicstaticvoidmain(Stringargs[]){精品文檔放心下載newmainframe()。show();}}*********************************************************感謝閱讀*********************************************************精品文檔放心下載2.Adddialog。java添加模塊packagebookmanager;importjava.awt。*;importjava.awt。event。*;importjava。util.LinkedList;謝謝閱讀importjavax。swing。*;publicclassadddialogimplementsActionListener{精品文檔放心下載JLabellabel[]=newJLabel[4];精品文檔放心下載JTextFieldtxt[]=newJTextField[4];精品文檔放心下載String[]ltitle={"圖書編號(hào)","圖書名稱”,"單 價(jià)”,”出版社”};感謝閱讀String[]btitle={”上一個(gè)",”下一個(gè)",”確 定”,"取消"};精品文檔放心下載JButtonbtn[]=newJButton[4];精品文檔放心下載JDialogdialog;JPanelp;LinkedListlist;publicadddialog(JFramef,intx,inty){感謝閱讀dialog=newJDialog(f,"增加”,true);謝謝閱讀dialog.setLocation(x,y);p=newJPanel();list=newLinkedList();p.setBorder(BorderFactory.createTitledBorder("請(qǐng)選擇操作”));謝謝閱讀p。setBorder(BorderFactory。createLineBorder(Color.red));精品文檔放心下載p.setBorder(BorderFactory。createBevelBorder(0,Color。red,Color。green));感謝閱讀p.setBorder(BorderFactory.createBevelBorder(0,Color。red,Color。感謝閱讀green,Color。blue ,Color。yellow ));精品文檔放心下載for(inti=0;i<ltitle。length;i++){感謝閱讀label[i]=newJLabel(ltitle[i]);謝謝閱讀label[i].setFont(newFont("宋體”,F(xiàn)ont.PLAIN,18));精品文檔放心下載txt[i]=newJTextField();btn[i]=newJButton(btitle[i]);謝謝閱讀btn[i].addActionListener(this);謝謝閱讀btn[i]。setFont(newFont(”幼圓”,Font.PLAIN,15));感謝閱讀dialog.add(label[i]);dialog.add(txt[i]);dialog.add(btn[i]);}dialog。setLayout(null);p。setBounds(10,150,310,160);謝謝閱讀p。setBackground(Color。green );謝謝閱讀label[0]。setBounds(10,10,90,25);txt[0]。setBounds(110,10,200,感謝閱讀25);label[1]。setBounds(10,45,90,25);txt[1].setBounds(110,45,200,25);label[2]。setBounds(10,80,90,25);txt[2]。setBounds(110,80,200,25);label[3]。setBounds(10,115,90,25);txt[3].setBounds(110,115,200,25);dialog.add(p);謝謝閱讀btn[0]。setBounds(60,180,80,25);btn[1]。setBounds(175,180,80,感謝閱讀25);btn[2].setBounds(60,250,80,25);btn[3].setBounds(175,250,80,25);精品文檔放心下載dialog.setSize(400,400);dialog。show();dialog。setDefaultCloseOperation(JFrame。DO_NOTHING_ON_CLOSE);謝謝閱讀}publicvoidactionPerformed(ActionEvente){intsize=list.size();感謝閱讀init();list。add(b);if(e.getSource()==btn[0]){謝謝閱讀bookb1=(book)list.get(size);謝謝閱讀size--;txt[0]。setText(b1.getid());精品文檔放心下載txt[1]。setText(b1.getname());感謝閱讀txt[2].setText(Float。toString(b1.getprice()));感謝閱讀txt[3].setText(b1。getpublish());感謝閱讀}if(e.getSource()==btn[1]){精品文檔放心下載//bookb2=(book)list.get(size);感謝閱讀size++;txt[0]。setText(b2。getid());謝謝閱讀txt[1].setText(b2.getname());感謝閱讀txt[2]。setText(Float.toString(b2.getprice()));精品文檔放心下載txt[3].setText(b2。getpublish());謝謝閱讀}if(e。getSource()==btn[2]){Stringid=txt[0].getText();Stringname=txt[1]。getText();謝謝閱讀floatprice=getprice(txt[2]。getText());Stringpublish=txt[3].getText();謝謝閱讀Objectstr[]={id,name,price,publish};dbcon.insert(dbcon。getconnectin(),str);謝謝閱讀}}privatefloatgetprice(Stringstr){精品文檔放心下載floatprice=0;try{price=Float。valueOf(str);}catch(Exceptionex){JOptionPane.showMessageDialog(null,”價(jià)格必須是數(shù)字,請(qǐng)重新輸入!”,”謝謝閱讀錯(cuò)誤",JOptionPane。WARNING_MESSAGE);感謝閱讀}returnprice;}//設(shè)定上一個(gè),下一個(gè)按鈕的可用性//privatevoidinit(){//if(list。size()==0)//{btn[0].setEnabled(false);btn[1]。setEnabled(false);}//else{btn[0].setEnabled(true);btn[1]。setEnabled(true);}//}}3。searchdialog.java查找模塊packagebookmanager;importjavax.swing.*;importjava。awt。*;importjava。awt.event.*;importjava。sql。Connection;謝謝閱讀importjava。sql。PreparedStatement;感謝閱讀importjava.sql。ResultSet;謝謝閱讀importjava.sql.SQLException;精品文檔放心下載importjava。util.LinkedList;感謝閱讀publicclasssearchdialogimplementsActionListener,ItemListener{JRadioButton[]radio=newJRadioButton[3];精品文檔放心下載ButtonGroupgroup;String[]rtitle={"圖書編號(hào)","圖書名稱",”出版社”};謝謝閱讀String[]btitle={”確定(Yes)”,"取消(Esc)"};精品文檔放心下載JTextFieldtxtfield[]=newJTextField[3];謝謝閱讀JButtonbtn[]=newJButton[2];謝謝閱讀JDialogdialog;searchresultst;publicsearchdialog(JFramef,intx,inty){精品文檔放心下載//初始化單選按鈕group=newButtonGroup();st=newsearchresult();for(inti=0;i〈radio.length;i++){謝謝閱讀radio[i]=newJRadioButton(rtitle[i]);精品文檔放心下載radio[i].addActionListener(this);精品文檔放心下載radio[i].setFont(newFont(”宋體”,F(xiàn)ont。PLAIN ,15));精品文檔放心下載radio[i]。addItemListener(this);感謝閱讀group。add(radio[i]);txtfield[i]=newJTextField();精品文檔放心下載txtfield[i]。setEditable(false);精品文檔放心下載}for(inti=0;i<2;i++){btn[i]=newJButton(btitle[i]);感謝閱讀btn[i]。addActionListener(this);謝謝閱讀btn[i].setFont(newFont("宋體",Font。PLAIN,15));感謝閱讀}dialog=newJDialog(f,"查詢",true);精品文檔放心下載//初始化radio[0]。setSelected(true);精品文檔放心下載txtfield[0].setEditable(true);謝謝閱讀dialog.setLocation(x,y);dialog。setLayout(null);//設(shè)定各個(gè)組件的邊界radio[0]。setBounds(10,10,90,25);txtfield[0].setBounds(110,感謝閱讀10,250,25);radio[1].setBounds(10,45,90,25);txtfield[1]。setBounds(110,45,250,感謝閱讀25);radio[2].setBounds(10,80,90,25);txtfield[2].setBounds(110,80,精品文檔放心下載250,25);for(inti=0;i<radio。length;i++){感謝閱讀dialog.add(radio[i]);dialog.add(txtfield[i]);}btn[0]。setBounds(20,135,120,25);btn[1].setBounds(200,135,120,精品文檔放心下載25);dialog。add(btn[0]);dialog。add(btn[1]);感謝閱讀dialog。setSize(400,250);dialog。setDefaultCloseOperation(JFrame。DISPOSE_ON_CLOSE );謝謝閱讀}publicvoidactionPerformed(ActionEvente){感謝閱讀if(e.getSource()==btn[0]){感謝閱讀st.init();Connectioncon=dbcon。getconnectin();謝謝閱讀PreparedStatementstmt=null;感謝閱讀ResultSetrs=null;LinkedListlist=newLinkedList();感謝閱讀try{if(radio[0].isSelected()){感謝閱讀stmt=con。prepareStatement("select*frombookwherebid謝謝閱讀like'%”+txtfield[0]。getText().trim()+”%’”);精品文檔放心下載}if(radio[1]。isSelected()){感謝閱讀stmt=con。prepareStatement("select*frombookwhere謝謝閱讀bnamelike'%"+txtfield[1]。getText().trim()+”%'");精品文檔放心下載}if(radio[2]。isSelected()){感謝閱讀stmt=con.prepareStatement(”select*frombookwhere精品文檔放心下載bpublishlike’%”+txtfield[2].getText().trim()+”%'”);謝謝閱讀}rs=stmt.executeQuery();while(rs.next()){Stringid=rs.getString(1);謝謝閱讀Stringname=rs。getString(2);謝謝閱讀Stringprice=rs.getString(3);精品文檔放心下載Stringpublish=rs。getString(4);精品文檔放心下載bookb=newbook(id,name,Float。valueOf(price),publish);list.add(b);精品文檔放心下載}for(inti=0;i<list.size();i++){精品文檔放心下載bookb=(book)list.get(i);Objectob[]={b。getid(),b.getname精品文檔放心下載(),b.getprice(),b.getpublish()};謝謝閱讀st.model.addRow(ob);}JOptionPane.showMessageDialog(null,"總共找到”+list。size()+”條記錄!","信息",JOptionPane.INFORMATION_MESSAGE);感謝閱讀st。show();catch(SQLExceptione1){TODOAuto—generatedcatchblock謝謝閱讀e1。printStackTrace();}}}publicvoiditemStateChanged(ItemEvente){for(inti=0;i〈radio.length;i++){謝謝閱讀if(radio[i].isSelected()){謝謝閱讀txtfield[i].setEditable(true);謝謝閱讀}elsetxtfield[i]。setEditable(false);精品文檔放心下載}}}4.searchresult.java查找結(jié)果packagebookmanager;importjavax。swing。*;importjavax。swing.table。DefaultTableModel;謝謝閱讀importjava。awt.*;importjava.awt。event.*;publicclasssearchresultextendsJFrameimplementsActionListener{JTabletable;謝謝閱讀DefaultTableModelmodel;String[]rtitle={"圖書編號(hào)”,"圖書名稱”,"單價(jià)”,”出版社"};感謝閱讀JDialogdialog;publicsearchresult(){super(”查詢結(jié)果”);model=newDefaultTableModel(rtitle,0);精品文檔放心下載table=newJTable(model);add(newJScrollPane(table),BorderLayout.CENTER);table.setRowHeight(25);謝謝閱讀table。setFont(newFont(”楷體”,Font。PLAIN ,18));感謝閱讀setSize(600,400);}publicvoidinit(){model.setRowCount(0);}publicvoidactionPerformed(ActionEvente){謝謝閱讀//以后擴(kuò)展用,暫不實(shí)現(xiàn)任何功能}}**************************謝謝閱讀5.dbcon.java數(shù)據(jù)庫(kù)連接類packagebookmanager;importjava。io.*;import。URL;importjava。sql.*;importjavax.swing。JOptionPane;感謝閱讀publicclassdbcon{publicfinalstaticConnectiongetconnectin(){謝謝閱讀Connectioncon=null;try{Class。forName(”com.microsoft。sqlserver.jdbc。SQLServerDriver");感謝閱讀Stringurl=”jdbc:sqlserver://localhost:1433;integratedSecurity=true;”;精品文檔放心下載con=DriverManager。getConnection(url);謝謝閱讀con.setCatalog(”book");}catch(ClassNotFoundExceptionex){精品文檔放心下載ex。printStackTrace();}catch(SQLExceptionex){ex.printStackTrace();}returncon;}//添加數(shù)據(jù)publicfinalstaticvoidinsert(Connectioncon,Objectobj[]){PreparedStatementstmt=null;謝謝閱讀try{stmt=con.prepareStatement(”insertintobookvalues(?,?,?,?)");謝謝閱讀stmt。setString(1,obj[0].toString());謝謝閱讀stmt.setString(2,obj[1]。toString());謝謝閱讀stmt。setFloat(3,F(xiàn)loat.valueOf(obj[2]。toString()));感謝閱讀stmt。setString(4,obj[3].toString());精品文檔放心下載stmt。execute();JOptionPane.showMessageDialog(null,"添加成功!”,”操作提示”,JOptionPane.NO_OPTION);精品文檔放心下載catch(SQLExce

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論