版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;/ -class Tsgl public static void main(String args) dbframe db = new dbframe("图书管理程序");/ 图书管理系统主界面class dbframe extends Frame implements ActionListener MenuBar daohang = new MenuBar(); / 建立菜单
2、栏Menu mfile = new Menu("功能"); / 建立“功能”菜单组Menu mhelp = new Menu("帮助"); / 建立“帮助”菜单组MenuItem mdenglu = new MenuItem("登陆");MenuItem mchaxun = new MenuItem("查询");MenuItem mtianjia = new MenuItem("添加");MenuItem mshanchu = new MenuItem("删除");MenuI
3、tem mexit = new MenuItem("退出");MenuItem mhelpp = new MenuItem("关于");Denglu pdenglu=new Denglu();Ptianjia ptianjia = new Ptianjia();Pmain pmain = new Pmain();Pchaxun pchaxun = new Pchaxun();Pshanchu pshanchu = new Pshanchu();dbframe(String s) / 在窗口上添加菜单选项setTitle(s);mfile.add(mden
4、glu);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(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0););setBounds(200, 200, 340, 250);setRes
5、izable(false);setVisible(true);mexit.addActionListener(this);mdenglu.addActionListener(this);mtianjia.addActionListener(this);mchaxun.addActionListener(this);mshanchu.addActionListener(this);mhelpp.addActionListener(this);validate(); / 窗口事件监听public void actionPerformed(ActionEvent e) if (e.getSource
6、() = 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);validat
7、e(); / 图书删除功能if (e.getSource() = mhelpp) JOptionPane.showMessageDialog(this, "欢迎使用图书管理系统", "关于本系统",JOptionPane.INFORMATION_MESSAGE); / 各功能菜单事件监听/class Ptianjia extends Panel implements ActionListener TextField tname, tauthor, tpublish, tdate, tcomment;Label lname, lauthor, lpubli
8、sh, ldate, lcomment;Button btn;Ptianjia() setLayout(null);btn = new Button("添加"); / 创建“添加”按钮tname = new TextField();tauthor = new TextField();tpublish = new TextField();tdate = new TextField();tcomment = new TextField(); / 创建5个文本框lname = new Label("书名");lauthor = new Label("
9、作者");lpublish = new Label("出版社");ldate = new Label("出版日期");lcomment = new Label("评论");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, 2
10、5);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
11、, 130, 220, 25);btn.setBounds(130, 160, 70, 25); / 设置按钮位置btn.addActionListener(this); / 设置按钮监听setSize(340, 250); / 设置窗口大小setBackground(Color.white); / 设置窗口背景颜色setVisible(true);validate(); public void actionPerformed(ActionEvent e) String sname = tname.getText();String sauthor = tauthor.getText();Str
12、ing spublish = tpublish.getText();String sdate = tdate.getText();String scomment = tcomment.getText();String insertstr = "insert into book values" + "(" + "'" + sname + "'"+ "," + "'" + sauthor + "'" + ","
13、; + "'" + spublish + "'" + ","+ "'" + sdate + "'" + "," + "'" + scomment + "'" + ")" / SQL语句Connection con;Statement sta;ResultSet rs;try Class.forName("oracle.jdbc.driver.OracleDri
14、ver"); / 加载JDBC驱动 catch (ClassNotFoundException ee) System.out.println("" + ee);try con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "sa", "orcl"); / 连接数据库sta = con.createStatement();sta.executeUpdate(insertstr); / 执行SQL语句con.clos
15、e(); / 关闭数据库tname.setText("");tauthor.setText("");tpublish.setText("");tdate.setText("");tcomment.setText(""); / 重新初始化文本框内容JOptionPane.showMessageDialog(this, "添加成功", "图书管理系统",JOptionPane.INFORMATION_MESSAGE); catch (SQLException
16、eee) System.out.println("" + eee);tname.setText("");tauthor.setText("");tpublish.setText("");tdate.setText("");tcomment.setText("");JOptionPane.showMessageDialog(this, "添加失败", "图书管理系统",JOptionPane.WARNING_MESSAGE);class
17、Pmain extends Panel / 窗口面板布局Label l1 = new Label("图书管理系统", Label.CENTER);Label l2 = new Label("计算机学院", Label.RIGHT);Label l3 = new Label("", Label.RIGHT);Label l4 = new Label("作者:JHL", Label.RIGHT);Pmain() setLayout(null);setBackground(Color.white);add(l1);add
18、(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();class Pchaxun extends Panel implements ActionListener / 图书查询Choice cchaxun;TextField tchaxun;Button btnchaxun;
19、TextArea tachaxun;Pchaxun() setLayout(null);cchaxun = new Choice(); / 创建下拉菜单cchaxun.add("书名");cchaxun.add("作者");cchaxun.add("出版社");tchaxun = new TextField();btnchaxun = new Button("查询"); / 创建按钮tachaxun = new TextArea(); / 创建多行文本框add(cchaxun);add(tchaxun);add(b
20、tnchaxun);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);bt
21、nchaxun.addActionListener(this);validate();public void actionPerformed(ActionEvent e) int i = cchaxun.getSelectedIndex();String s = tchaxun.getText();if (s.equals("")JOptionPane.showMessageDialog(this, "查询内容不能为 空", "查询系统",JOptionPane.WARNING_MESSAGE);else Connection con
22、;Statement sql;ResultSet rs;try Class.forName("oracle.jdbc.driver.OracleDriver"); / 加载JDBC驱动 catch (ClassNotFoundException ee) System.out.println("" + ee);try con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:orcl", "sa", "orcl");/ 连
23、接数据库sql = con.createStatement();if (i = 0) / 根据下拉菜单的选项执行不同的SQL语句rs = sql.executeQuery("select * from book where bookName ="+ "'" + s + "'");else if (i = 1)rs = sql.executeQuery("select * from book where author ="+ "'" + s + "'&qu
24、ot;);elsers = sql.executeQuery("select * from book where publisher ="+ "'" + s + "'");tachaxun.setText("");String panduan = "false"while (rs.next() panduan = "true"tachaxun.append("书名:" + rs.getString(1) + "n");t
25、achaxun.append("作者:" + rs.getString(2) + "n");tachaxun.append("出版社:" + rs.getString(3) + "n");tachaxun.append("出版日期:" + rs.getString(4) + "n");tachaxun.append("评论:" + rs.getString(5) + "n"); / 显示查询到的图书信息rs = sql.executeQ
26、uery("select count(*) from book"); / 统计所有图书数while (rs.next() tachaxun.append("图书馆暂有" + rs.getString(1) + "本图书"); / 显示所有图书数量信息con.close(); / 关闭数据库if (panduan.equals("false")JOptionPane.showMessageDialog(this, "没有该记录", "查询系统",JOptionPane.WARN
27、ING_MESSAGE); catch (SQLException eee) System.out.println(eee);class Pshanchu extends Panel implements ActionListener / 删除功能模块Choice cshanchu;TextField tshanchu;Button btnshanchu;Label l1 = new Label("", Label.CENTER);Label l2 = new Label("计算机学院", Label.RIGHT);Label l3 = new Labe
28、l("", Label.RIGHT);Label l4 = new Label("作者:ZCS", Label.RIGHT);Pshanchu() setLayout(null);cshanchu = new Choice(); / 创建下拉菜单cshanchu.add("书名");tshanchu = new TextField();btnshanchu = new Button("删除"); / 创建按钮add(cshanchu);add(tshanchu);add(btnshanchu);add(l1);ad
29、d(l2);add(l3);add(l4); / 添加标签、按钮等到窗口面板tshanchu.setText("");cshanchu.setBounds(10, 10, 65, 20);tshanchu.setBounds(85, 10, 180, 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)
30、;cshanchu.select(0);setSize(340, 250); / 设置窗口大小setBackground(Color.white);setVisible(true);btnshanchu.addActionListener(this);validate();public void actionPerformed(ActionEvent e) String s = tshanchu.getText();if (s.equals("")JOptionPane.showMessageDialog(this, "请输入要删除的图书", "
31、;删除功能",JOptionPane.WARNING_MESSAGE);else Connection con;Statement sql;ResultSet rs;try Class.forName("oracle.jdbc.driver.OracleDriver"); catch (ClassNotFoundException ee) System.out.println("" + ee);try con = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:
32、orcl", "sa", "orcl");sql = con.createStatement();rs = sql.executeQuery("select * from book where bookName ="+ "'" + s + "'");if (!rs.next()JOptionPane.showMessageDialog(this, "没有该图书", "删除功能",JOptionPane.WARNING_MESSAG
33、E);else int n = JOptionPane.showConfirmDialog(this, "确认删除吗?","删除功能", JOptionPane.YES_NO_OPTION);if (n = JOptionPane.YES_OPTION) sql.executeUpdate("delete from book where bookName ="+ "'" + s + "'");JOptionPane.showMessageDialog(this, "删除成功", "删除功能",JOptionPane.INFORMATION_MESSAGE);tshanchu.setText(""); elsetshanchu.setText("");con.close(); ca
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 关于2026年供应商质量管理体系改进的通知(7篇)范文
- 基于TRIZ理论与人工智能的智康姿态分析系统设计与实现
- 智慧启航诚信导向:小学诚信与智慧主题班会课件
- 电子竞技行业营销及广告推广计划
- 文件归档流程标准化指南
- 活动帐篷起火初期灭火负责人预案
- 2026清华附中天府学校第二轮考核招聘事业单位人员13人(四川)笔试题库附完整答案详解(夺冠)
- 智能会议系统会议记录管理指南
- 2026广东肇庆学院第一批招聘高层次和紧缺人才2人参考题库及答案详解【各地真题】
- 科学预防感染线守护身心健康阳光万里小学主题班会课件
- 铁路装卸安全课件
- 麻袋装填护坡施工方案
- 销售配件管理制度大全
- 中暑热衰竭电解质紊乱护理查房
- DGTJ08-2240-2017 道路注浆加固技术规程
- 药品技术转移管理制度
- 【鄂尔多斯】2024年内蒙古鄂尔多斯职业学院人才引进39人笔试附带答案详解
- DB32-T 4910-2024 大水面生态渔业资源监测与资源量评估技术规范 湖泊与水库
- DB52T 1161-2016 贵州省旅游购物场所等级划分与评定
- NB-T35026-2022混凝土重力坝设计规范
- 标准施工招标文件2007版
评论
0/150
提交评论