图书管理系统---java代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjava.util.*;importjavax.swing.*;//---------------------------------------------------------------------------------------------------------classTsgl{publicstaticvoidmain(Stringargs[]){dbframedb=newdbframe(图书管理程序);}}//图书管理系统主界面classdbframeextendsFrameimplementsActionListener{MenuBardaohang=newMenuBar();//建立菜单栏Menumfile=newMenu(功能);//建立“功能”菜单组Menumhelp=newMenu(帮助);//建立“帮助”菜单组MenuItemmdenglu=newMenuItem(登陆);MenuItemmchaxun=newMenuItem(查询);MenuItemmtianjia=newMenuItem(添加);MenuItemmshanchu=newMenuItem(删除);MenuItemmexit=newMenuItem(退出);MenuItemmhelpp=newMenuItem(关于);Denglupdenglu=newDenglu();Ptianjiaptianjia=newPtianjia();Pmainpmain=newPmain();Pchaxunpchaxun=newPchaxun();Pshanchupshanchu=newPshanchu();dbframe(Strings){//在窗口上添加菜单选项setTitle(s);mfile.add(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(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});setBounds(200,200,340,250);setResizable(false);setVisible(true);mexit.addActionListener(this);mdenglu.addActionListener(this);mtianjia.addActionListener(this);mchaxun.addActionListener(this);mshanchu.addActionListener(this);mhelpp.addActionListener(this);validate();}//窗口事件监听publicvoidactionPerformed(ActionEvente){if(e.getSource()==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);validate();}//图书删除功能if(e.getSource()==mhelpp){JOptionPane.showMessageDialog(this,欢迎使用图书管理系统,关于本系统,JOptionPane.INFORMATION_MESSAGE);}}//各功能菜单事件监听}//classPtianjiaextendsPanelimplementsActionListener{TextFieldtname,tauthor,tpublish,tdate,tcomment;Labellname,lauthor,lpublish,ldate,lcomment;Buttonbtn;Ptianjia(){setLayout(null);btn=newButton(添加);//创建“添加”按钮tname=newTextField();tauthor=newTextField();tpublish=newTextField();tdate=newTextField();tcomment=newTextField();//创建5个文本框lname=newLabel(书名);lauthor=newLabel(作者);lpublish=newLabel(出版社);ldate=newLabel(出版日期);lcomment=newLabel(评论);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,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(90,130,220,25);btn.setBounds(130,160,70,25);//设置按钮位置btn.addActionListener(this);//设置按钮监听setSize(340,250);//设置窗口大小setBackground(Color.white);//设置窗口背景颜色setVisible(true);validate();}publicvoidactionPerformed(ActionEvente){Stringsname=tname.getText();Stringsauthor=tauthor.getText();Stringspublish=tpublish.getText();Stringsdate=tdate.getText();Stringscomment=tcomment.getText();Stringinsertstr=insertintobookvalues+(+'+sname+'+,+'+sauthor+'+,+'+spublish+'+,+'+sdate+'+,+'+scomment+'+);//SQL语句Connectioncon;Statementsta;ResultSetrs;try{Class.forName(oracle.jdbc.driver.OracleDriver);//加载JDBC驱动}catch(ClassNotFoundExceptionee){System.out.println(+ee);}try{con=DriverManager.getConnection(jdbc:oracle:thin:@localhost:1521:orcl,sa,orcl);//连接数据库sta=con.createStatement();sta.executeUpdate(insertstr);//执行SQL语句con.close();//关闭数据库tname.setText();tauthor.setText();tpublish.setText();tdate.setText();tcomment.setText();//重新初始化文本框内容JOptionPane.showMessageDialog(this,添加成功,图书管理系统,JOptionPane.INFORMATION_MESSAGE);}catch(SQLExceptioneee){System.out.println(+eee);tname.setText();tauthor.setText();tpublish.setText();tdate.setText();tcomment.setText();JOptionPane.showMessageDialog(this,添加失败,图书管理系统,JOptionPane.WARNING_MESSAGE);}}}classPmainextendsPanel{//窗口面板布局Labell1=newLabel(图书管理系统,Label.CENTER);Labell2=newLabel(计算机学院,Label.RIGHT);Labell3=newLabel(,Label.RIGHT);Labell4=newLabel(作者: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,80,22);setSize(340,250);setVisible(true);validate();}}classPchaxunextendsPanelimplementsActionListener{//图书查询Choicecchaxun;TextFieldtchaxun;Buttonbtnchaxun;TextAreatachaxun;Pchaxun(){setLayout(null);cchaxun=newChoice();//创建下拉菜单cchaxun.add(书名);cchaxun.add(作者);cchaxun.add(出版社);tchaxun=newTextField();btnchaxun=newButton(查询);//创建按钮tachaxun=newTextArea();//创建多行文本框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,305,145);cchaxun.select(0);//下拉菜单的初始选项setSize(340,250);//设置窗口大小setBackground(Color.white);setVisible(true);btnchaxun.addActionListener(t

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功