版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、图书管理系统-java代码图书管理系统-java代码:importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjava.util.*;importjavax.swing.*;/-classTsglpublicstaticvoidmain(Stringargs)dbframedb=newdbframe(图书管理程序);图书管理系统主界面classdbframeextendsFrameimplementsActionListenerMenuBardaohang=newMenuBar();/成立菜单栏Menumfile=newMe
2、nu(功能);/成立“功能”菜单组Menumhelp=newMenu(帮助);/成立“帮助”菜单组MenuItemmdenglu=newMenuItem(登岸);MenuItemmchaxun=newMenuItem(查问);MenuItemmtianjia=newMenuItem(增添);MenuItemmshanchu=newMenuItem(删除);MenuItemmexit=newMenuItem(退出);MenuItemmhelpp=newMenuItem(对于);Denglupdenglu=newDenglu();Ptianjiaptianjia=newPtianjia();Pma
3、inpmain=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)
4、;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.addAction
5、Listener(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)rem
6、oveAll();add(pchaxun);validate();/图书查问功能if(e.getSource()=mshanchu)removeAll();add(pshanchu);validate();/图书删除功能if(e.getSource()=mhelpp)JOptionPane.showMessageDialog(this,欢迎使用图书管理系统,对于本系统,JOptionPane.INFORMATION_MESSAGE);/各功能菜单事件监听/classPtianjiaextendsPanelimplementsActionListenerTextFieldtname,tautho
7、r,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(作者);lpublis
8、h=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);t
9、author.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);/设置按钮监听setSi
10、ze(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=insert
11、intobookvalues+(+sname+,+sauthor+,+spublish+,+sdate+,+scomment+);/SQLConnectioncon;Statementsta;ResultSetrs;try语句Class.forName(oracle.jdbc.driver.OracleDriver);/加载JDBC驱动catch(ClassNotFoundExceptionee)System.out.println(+ee);trycon=DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl,sa,o
12、rcl);/连结数据库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.
13、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=newLabe
14、l(,Label.RIGHT);Labell4=newLabel(Pmain()setLayout(null);作者:JHL,Label.RIGHT);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();classPcha
15、xunextendsPanelimplementsActionListener/Choicecchaxun;TextFieldtchaxun;Buttonbtnchaxun;TextAreatachaxun;Pchaxun()setLayout(null);图书查问cchaxun=newChoice();/创立下拉菜单cchaxun.add(书名);cchaxun.add(作者);cchaxun.add(第一版社);tchaxun=newTextField();btnchaxun=newButton(查问);/创立按钮tachaxun=newTextArea();/创立多行文本框add(cch
16、axun);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);btnchax
17、un.addActionListener(this);validate();publicvoidactionPerformed(ActionEvente)inti=cchaxun.getSelectedIndex();Strings=tchaxun.getText();if(s.equals()JOptionPane.showMessageDialog(this,查问内容不可以为空,查问系统,JOptionPane.WARNING_MESSAGE);elseConnectioncon;Statementsql;ResultSetrs;tryClass.forName(oracle.jdbc.d
18、river.OracleDriver);/加载JDBC驱动catch(ClassNotFoundExceptionee)System.out.println(+ee);trycon=DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl,sa,orcl);/连结数据库sql=con.createStatement();if(i=0)/依据下拉菜单的选项履行不一样的SQL语句rs=sql.executeQuery(select*frombookwherebookName=+s+);elseif(i=1)rs=sql.exe
19、cuteQuery(select*frombookwhereauthor=+s+);elsers=sql.executeQuery(select*frombookwherepublisher=+s+);tachaxun.setText();Stringpanduan=false;while(rs.next()panduan=true;tachaxun.append(书名:+rs.getString(1)+n);tachaxun.append(作者:+rs.getString(2)+n);tachaxun.append(第一版社:+rs.getString(3)+n);tachaxun.appe
20、nd(第一版日期:+rs.getString(4)+n);tachaxun.append(议论:+rs.getString(5)+n);/显示查问到的图书信息rs=sql.executeQuery(selectcount(*)frombook);/统计全部图书数while(rs.next()tachaxun.append(图书室暂有+rs.getString(1)+本图书);/显示全部图书数目信息con.close();/封闭数据库if(panduan.equals(false)JOptionPane.showMessageDialog(this,没有该记录,查问系统,JOptionPane.
21、WARNING_MESSAGE);catch(SQLExceptioneee)System.out.println(eee);classPshanchuextendsPanelimplementsActionListener/删除功能模块Choicecshanchu;TextFieldtshanchu;Buttonbtnshanchu;Labell1=newLabel(,Label.CENTER);Labell2=newLabel(计算机学院,Label.RIGHT);Labell3=newLabel(,Label.RIGHT);Labell4=newLabel(Pshanchu()setLa
22、yout(null);作者:ZCS,Label.RIGHT);cshanchu=newChoice();/创立下拉菜单cshanchu.add(书名);tshanchu=newTextField();btnshanchu=newButton(删除);/创立按钮add(cshanchu);add(tshanchu);add(btnshanchu);add(l1);add(l2);add(l3);add(l4);/增添标签、按钮等到窗口面板tshanchu.setText();cshanchu.setBounds(10,10,65,20);tshanchu.setBounds(85,10,180,
23、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);cshanchu.select(0);setSize(340,250);/设置窗口大小setBackground(Color.white);setVisible(true);btnshanchu.addActionListener(this);validate();publicvoidactionP
24、erformed(ActionEvente)Strings=tshanchu.getText();if(s.equals()JOptionPane.showMessageDialog(this,请输入要删除的图书,删除功能,JOptionPane.WARNING_MESSAGE);elseConnectioncon;Statementsql;ResultSetrs;tryClass.forName(oracle.jdbc.driver.OracleDriver);catch(ClassNotFoundExceptionee)System.out.println(+ee);trycon=Driv
25、erManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl,sa,orcl);sql=con.createStatement();rs=sql.executeQuery(select*frombookwherebookName=+s+);if(!rs.next()JOptionPane.showMessageDialog(this,没有该图书,删除功能,JOptionPane.WARNING_MESSAGE);elseintn=JOptionPane.showConfirmDialog(this,确认删除吗?,删除功能,JOptionPane.YES_NO_OPTION);if(n=JOptionPane.YES_OPTION)sql.executeUpdate(deletefrombookwherebookName=+s+);JOptionPane.showMessageDialog(this,删除成功,删除功能,JOptionPane.INFORMATION_MESSAGE);tshanchu.setText();elsetshanchu.setText();con.close();catch(SQLExceptioneee)System.out.println(eee);classDengluextendsP
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农业科技领域农业技术推广员技术成果转化KPI考核表
- 催办函要求财务部重新核对账目4篇
- 关于软件开发进度反馈回复函5篇
- 共建和谐校园杜绝欺凌行为小学主题班会课件
- 走进科学世界:探索科学的奥秘小学主题班会课件
- 项目管理流程规范与执行力提升指导手册
- 危险货物运输企业主要负责人运行操作安全操作规程
- 销售目标达成率评估反馈通知3篇范本
- 2026燃气职业技能鉴定试卷附答案详解
- 有色金属冶炼企业检修员运行操作安全操作规程
- 2026年环境监测人员持证上岗考核试题上、下册附答案
- 2026年海南省万宁市高一数学下册期末考试模拟测试卷(考点提分)附答案
- 2026年社区网格员综合知识笔试考试题库及参考答案
- 2026年计算机一级考试WPS基础练习题含答案
- 成都兴城投资集团有限公司成都蓉城城市管理服务有限公司2026年6月校园招聘笔试参考试题及答案详解
- 商铺应急处置流程
- 学校老校区改造提升项目方案投标文件(技术方案)
- DB51T 5049-2018 四川省通风与空调工程施工工艺标准
- 拓展培训项目-:85个常规拓展项目介绍
- 智慧医疗综合监管平台建设整体解决方案
- 压力表基础知识课件
评论
0/150
提交评论