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

上传人:工**** 文档编号:397349056 上传时间:2023-01-14 格式:DOC 页数:11 大小:41KB
返回 下载 相关 举报
图书管理系统---java代码_第1页
第1页 / 共11页
图书管理系统---java代码_第2页
第2页 / 共11页
图书管理系统---java代码_第3页
第3页 / 共11页
图书管理系统---java代码_第4页
第4页 / 共11页
图书管理系统---java代码_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《图书管理系统---java代码》由会员分享,可在线阅读,更多相关《图书管理系统---java代码(11页珍藏版)》请在金锄头文库上搜索。

1、-import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import java*.swing.*;/ -class Tsgl public static void main(String args) dbframe db = new dbframe(图书管理程序);/ 图书管理系统主界面class dbframe e*tends Frame implements ActionListener MenuBar daohang = new MenuBar(); / 建立菜单栏Menu mfile

2、 = new Menu(功能); / 建立功能”菜单组Menu mhelp = new Menu(帮助); / 建立帮助”菜单组MenuItem mdenglu = new MenuItem(登陆);MenuItem mcha*un = new MenuItem(查询);MenuItem mtianjia = new MenuItem(添加);MenuItem mshanchu = new MenuItem(删除);MenuItem me*it = new MenuItem(退出);MenuItem mhelpp = new MenuItem(关于);Denglu pdenglu=new De

3、nglu();Ptianjia ptianjia = new Ptianjia();Pmain pmain = new Pmain();Pcha*un pcha*un = new Pcha*un();Pshanchu pshanchu = new Pshanchu();dbframe(String s) / 在窗口上添加菜单选项setTitle(s);mfile.add(mdenglu);mfile.add(mtianjia);mfile.add(mcha*un);mfile.add(mshanchu);mfile.add(me*it);mhelp.add(mhelpp);daohang.ad

4、d(mfile);daohang.add(mhelp);setMenuBar(daohang);add(pmain);addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.e*it(0););setBounds(200, 200, 340, 250);setResizable(false);setVisible(true);me*it.addActionListener(this);mdenglu.addActionListener(this);mtianjia.addActi

5、onListener(this);mcha*un.addActionListener(this);mshanchu.addActionListener(this);mhelpp.addActionListener(this);validate(); / 窗口事件监听public void actionPerformed(ActionEvent e) if (e.getSource() = me*it)System.e*it(0);if(e.getSource()=mdenglu)removeAll();add(pdenglu);validate();if (e.getSource() = mt

6、ianjia) removeAll();add(ptianjia);validate(); / 图书添加功能if (e.getSource() = mcha*un) removeAll();add(pcha*un);validate(); / 图书查询功能if (e.getSource() = mshanchu) removeAll();add(pshanchu);validate(); / 图书删除功能if (e.getSource() = mhelpp) JOptionPane.showMessageDialog(this, 欢迎使用图书管理系统, 关于本系统,JOptionPane.IN

7、FORMATION_MESSAGE); / 各功能菜单事件监听/class Ptianjia e*tends Panel implements ActionListener Te*tField tname, tauthor, tpublish, tdate, tment;Label lname, lauthor, lpublish, ldate, lment;Button btn;Ptianjia() setLayout(null);btn = new Button(添加); / 创建添加”按钮tname = new Te*tField();tauthor = new Te*tField();

8、tpublish = new Te*tField();tdate = new Te*tField();tment = new Te*tField(); / 创建5个文本框lname = new Label(书名);lauthor = new Label(作者);lpublish = new Label();ldate = new Label(出版日期);lment = new Label(评论);add(lname);add(tname);add(lauthor);add(tauthor);add(lpublish);add(tpublish);add(ldate);add(tdate);ad

9、d(lment);add(tment);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,

10、 100, 220, 25);lment.setBounds(10, 130, 70, 25);tment.setBounds(90, 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) Stri

11、ng sname = tname.getTe*t();String sauthor = tauthor.getTe*t();String spublish = tpublish.getTe*t();String sdate = tdate.getTe*t();String sment = tment.getTe*t();String insertstr = insert into book values + ( + + sname + + , + + sauthor + + , + + spublish + + ,+ + sdate + + , + + sment + + ); / SQL语句

12、Connection con;Statement sta;ResultSet rs;try Class.forName(oracle.jdbc.driver.OracleDriver); / 加载JDBC驱动 catch (ClassNotFoundE*ception ee) System.out.println( + ee);try con = DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl, sa, orcl); / 连接数据库sta = con.createStatement();sta.e*ecuteUp

13、date(insertstr); / 执行SQL语句con.close(); / 关闭数据库tname.setTe*t();tauthor.setTe*t();tpublish.setTe*t();tdate.setTe*t();tment.setTe*t(); / 重新初始化文本框容JOptionPane.showMessageDialog(this, 添加成功, 图书管理系统,JOptionPane.INFORMATION_MESSAGE); catch (SQLE*ception eee) System.out.println( + eee);tname.setTe*t();tauthor.setTe*t();tpublish.setTe*t();tdate.setTe*t();tment.setTe*t();JOptionPane.showMessageDialog(this, 添加

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 商业计划书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号