




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、目 录题目简述 - 01需求分析 - 01数据结构 - 01功能模块 - 02程序设计 - 02运行截图 - 04分析总结 - 08程序源码 - 08图书信息管理系统题目简述:题目名称:图书信息管理系统要求:使用图形用户界面,用数据库建立1或2个图书信息表,能连接数据库并实现查询、增加、删除、修改等功能。需求分析:图书信息管理系统应该具备图书的信息管理功能和流通管理功能。其中,信息管理功能包括查找,增加,修改,删除,显示全部信息等模块。流通管理功能包括图书借阅,归还等模块。因此分别设计各个模块,实现不同的功能。数据结构:用SQL Sever 建立数据库的表,用一张表存放图书的ID号码,图书名称
2、,图书的所有者,图书状态,图书的使用者(允许为空)。具体设计如下图所示:图书ID,图书名称,图书所有者,图书的状态,图书使用者(允许为空)均为varchar(50)类型,在Java中可以方便的查询。图书存储信息的具体内容如下图所示:功能模块:主程序窗口系统操作图书信息管理图书流通管理 退出增加图书显示图书编辑图书查找图书删除图书图书借阅图书归还程序设计:主框架设计:主框架上方包含三个按钮,分别是“系统管理”、“图书信息管理”和“图书流通管理”,定义JMenuBar类的对象、JMenu类的对象和JMenuItem类的对象,分别表示菜单栏、菜单组和菜单选项,然后调用初始化函数,将不同类的对象通过s
3、etText()函数设定不同的文本,然后将其添加到窗口容器中。对每个按钮分别添加不同的消息监听,响应相应的消息,调用不同的类完成不同的功能。消息监听功能详见源代码bookMain类。图书信息管理模块包括增加图书,删除图书,编辑图书,查找图书和显示图书信息。具体的方法实现在bookBean中实现,当用户点击相应的按钮时,消息监听模块就会调用bookBean的构造函数产生一个bookBean的对象,然后通过对象调用bookBean类中的相应方法,完成事件的相应。增加图书信息模块:调用bookAdd类的构造函数产生一个该类的对象,在初始化函数中显示信息输入对话框,提示用户输入图书ID,图书名称和图书
4、所有者,由于刚增加的图书没有被借阅,所以图书状态和图书使用者为默认值,分别为空闲和null,因此用户不必输入这两个属性值。完成输入后,点击确定按钮,消息监听模块将调用bookBean的构造函数产生一个该类的对象,通过该对象调用bookBean的bookAdd函数,执行SQL语句,通过insert语句完成图书信息的增加插入功能。删除图书信息模块:调用bookDel类的构造函数产生一个该类的对象,在初始化函数中显示信息输入对话框,提示用户输入要删除图书的ID。完成输入后,点击确定按钮,消息监听模块将调用bookBean的构造函数产生一个该类的对象,通过该对象调用bookBean的bookDel函数
5、,执行删除的SQL语句,通过delete语句完成图书信息的删除功能。修改图书信息模块:点击按钮后调用bookEdit类的构造函数产生一个该类的对象,在初始化函数中显示信息输入对话框,提示用户输入要修改图书的ID和其他图书信息,用户将信息输入完成后,点击确定按钮,消息监听模块将调用bookBean的构造函数产生一个该类的对象,通过该对象调用bookBean的bookEdit函数,执行修改的SQL语句,通过update语句完成图书信息的编辑功能。查找图书信息模块:点击按钮后调用bookSearch类的构造函数产生一个该类的对象,在初始化函数中显示信息输入对话框,提示用户输入要查找图书的ID,用户将
6、信息输入完成后,点击确定按钮,消息监听模块将调用bookResult的构造函数产生一个该类的对象,通过该对象的构造函数,执行查找的SQL语句,通过select语句完成图书信息的查找功能,然后构造图标,将查询到的信息显示在图表中。显示图书信息模块:点击按钮后调用bookDisplay类的构造函数产生一个该类的对象,在该对象的构造函数中调用bookAllSearch函数,查询所有的图书信息,显示在表格中。 图书流通管理模块包含图书的借阅与归还功能,其实就是对数据库中的某一记录集的某一属性进行修改。图书借阅模块:用户输入要借阅的图书名称和本人姓名,点击确定后,将调用bookBean的构造函数产生一个
7、对象,通过该对象调用bookBook函数,修改数据库中的信息,将图书状态属性变为已借,将图书用户属性变为用户姓名,完成图书的借阅功能。图书归还模块:用户输入要归还的图书名称,点击确定后,将调用bookBean的构造函数产生一个对象,通过该对象调用bookReturn函数,修改数据库中的信息,把图书的状态置为空闲,将图书用户置为空,从而完成图书的归还功能。备注:报告此部分未附源代码,详见程序源码部分。运行截图:图书信息增加:图书信息修改:图书信息查询:图书信息删除:图书信息显示:图书借阅:图书归还:分析总结:本程序在数据库设计方面可以改为多张表存储的方式,用三张表来记录图书信息,借阅关系和学生信
8、息,这样可以减少数据冗余,还可以增加一些其他功能,比如图书挂失等功能。由于刚刚接触到Java界面设计,所以本程序在界面设计方面还有有待改进的地方。程序源码:DatabaseConn.javapackage bookDB;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DatabaseConn private Statement stmt = n
9、ull;ResultSet rs = null;private Connection conn = null;String sql;public DatabaseConn() public void OpenConn() throws Exception tryClass.forName(sun.jdbc.odbc.JdbcOdbcDriver);conn = DriverManager.getConnection(jdbc:odbc:library);catch (Exception e) System.err.println(数据库连接:+e.getMessage();public Res
10、ultSet executeQuery(String sql)stmt = null;rs = null;trystmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);rs = stmt.executeQuery(sql);catch (SQLException e)System.err.println(查询数据:+e.getMessage();return rs;public void executeUpdate(String sql)stmt = null;rs =
11、null;trystmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);rs = stmt.executeQuery(sql);mit();catch (SQLException e)System.err.println(更新数据:+e.getMessage();public void closeStmt()try stmt.close();catch (SQLException e)System.err.println(释放对象:+e.getMessag
12、e();public void closeConn()try conn.close();catch (SQLException ex)System.err.println(释放对象:+ex.getMessage();public static String toGBK(String str)tryif(str = null)str = null;elsestr = new String(str.getBytes(ISO-8859-1),GBK);catch (Exception e)System.out.println(e);return str;package bookDB;import j
13、ava.awt.AWTEvent;import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JFrame;import javax.swing.JMenu;import javax.sw
14、ing.JMenuBar;import javax.swing.JMenuItem;bookMain.javapublic class bookMain extends JFrame implements ActionListenerprivate static final long serialVersionUID = 1L;/-建立菜单栏-JMenuBar mainMenu = new JMenuBar();/-建立系统管理菜单组- JMenu menuSystem = new JMenu(); JMenuItem itemExit = new JMenuItem(); JMenu men
15、ubook = new JMenu(); JMenu menuevent = new JMenu(); JMenuItem itemAdd = new JMenuItem(); JMenuItem itemEdit = new JMenuItem(); JMenuItem itemDelete = new JMenuItem(); JMenuItem itemSelect = new JMenuItem(); JMenuItem itemBook = new JMenuItem(); JMenuItem itemReturn = new JMenuItem(); JMenuItem itemD
16、isplay = new JMenuItem(); /-创建窗体模板对象- public static bookInfo m_stu = new bookInfo(); public bookMain() enableEvents(AWTEvent.WINDOW_EVENT_MASK); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setSize(600,480); this.setTitle(图书管理系统); try Init(); catch (Exception e) e.printStac
17、kTrace(); private void Init() throws Exception Container contentPane = this.getContentPane(); contentPane.setLayout(new BorderLayout(); /-添加菜单组- menuSystem.setText(系统操作); menuSystem.setFont(new Font(Dialog,0,12); menubook.setText(图书信息管理); menubook.setFont(new Font(Dialog,0,12); menuevent.setText(图书流
18、通管理); menuevent.setFont(new Font(Dialog,0,12); /-生成系统管理菜单组- itemExit.setText(退出); itemExit.setFont(new Font(Dialog,0,12); /-生成学生菜单组- itemAdd.setText(增加图书); itemAdd.setFont(new Font(Dialog,0,12); itemEdit.setText(修改信息); itemEdit.setFont(new Font(Dialog,0,12); itemDelete.setText(删除图书); itemDelete.setF
19、ont(new Font(Dialog,0,12); itemSelect.setText(查询); itemSelect.setFont(new Font(Dialog,0,12); itemDisplay.setText(显示全部信息); itemDisplay.setFont(new Font(Dialog,0,12);/-生成管理事务菜单组- itemBook.setText(图书借阅); itemBook.setFont(new Font(Dialog,0,12); itemReturn.setText(图书归还); itemReturn.setFont(new Font(Dialo
20、g,0,12); menuSystem.add(itemExit); menubook.add(itemAdd); menubook.add(itemEdit); menubook.add(itemDelete); menubook.add(itemSelect); menubook.add(itemDisplay); menuevent.add(itemBook); menuevent.add(itemReturn); /-组合菜单栏- mainMenu.add(menuSystem); mainMenu.add(menubook); mainMenu.add(menuevent); thi
21、s.setJMenuBar(mainMenu); /添加事件监听 itemExit.addActionListener(this); itemAdd.addActionListener(this); itemEdit.addActionListener(this); itemDelete.addActionListener(this); itemSelect.addActionListener(this); itemBook.addActionListener(this); itemReturn.addActionListener(this); itemDisplay.addActionLis
22、tener(this); setVisible(true); this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e)System.exit(0); ); public void actionPerformed(ActionEvent e) Object obj = e.getSource(); if(obj = itemExit)System.exit(0); else if(obj = itemAdd) bookAdd asi = new bookAdd(); /asi.downI
23、nit(); asi.pack(); asi.setVisible(true); else if(obj = itemEdit) bookEdit esi = new bookEdit(); /esi.downInit(); esi.pack(); esi.setVisible(true); else if(obj = itemDelete) bookDel dsi = new bookDel(); /dsi.downInit(); dsi.pack(); dsi.setVisible(true); else if(obj = itemSelect) bookSearch sbid = new
24、 bookSearch(); sbid.pack(); sbid.setVisible(true); else if(obj = itemBook) bookBook sboo = new bookBook(); sboo.pack(); sboo.setVisible(true); else if(obj = itemReturn) bookReturn sre = new bookReturn(); sre.pack(); sre.setVisible(true); else if(obj = itemDisplay) bookDisplay sre = new bookDisplay()
25、; sre.pack(); sre.setVisible(true); public static void main(String args)new bookMain();bookAdd.javapackage bookDB;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class bookAdd extends JFrame implements ActionListenerContainer c;JLabel jLabel1 = new JLabel();JLabel jLabel2 = new
26、 JLabel();JLabel jLabel3 = new JLabel();JLabel jLabel4 = new JLabel();JLabel jLabel5 = new JLabel();JTextField sid = new JTextField(10);JTextField sname = new JTextField(10);JTextField sowner = new JTextField(10);JTextField sstatus = new JTextField(10);JTextField suser = new JTextField(10);JButton a
27、ddconfirm = new JButton();public bookAdd()this.setTitle(增加图书信息);this.setResizable(false);tryInit();catch (Exception e)e.printStackTrace();/设置居中Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height - 300)/2 +45);publ
28、ic void Init() throws Exceptionthis.setSize(300,500);c = this.getContentPane();c.setLayout(new FlowLayout();jLabel1.setText(图书ID: );jLabel1.setFont(new Font(Dialog,0,12);c.add(jLabel1);sid.setText(null);sid.setFont(new Font(Dialog,0,12);c.add(sid);jLabel2.setText(图书名称: );jLabel2.setFont(new Font(Dia
29、log,0,12);c.add(jLabel2);sname.setText(null);sname.setFont(new Font(Dialog,0,12);c.add(sname);jLabel3.setText(图书所有者: );jLabel3.setFont(new Font(Dialog,0,12);c.add(jLabel3);sowner.setText(null);sowner.setFont(new Font(Dialog,0,12);c.add(sowner);addconfirm.setText(确认增加);addconfirm.setFont(new Font(Dia
30、log,0,12);c.add(addconfirm);addconfirm.addActionListener(this);public void actionPerformed(ActionEvent e)Object obj = e.getSource();if(obj = addconfirm)bookBean rs = new bookBean();rs.bookAdd(sid.getText(),sname.getText(),sowner.getText();this.dispose();bookInfo.javapackage bookDB;public class bookI
31、nfo String m_book_id;String m_book_name;String m_book_owner;String m_book_status;String m_book_user;bookEdit.javapackage bookDB;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class bookEdit extends JFrame implements ActionListenerContainer c;JLabel jLabel1 = new JLabel();JLabe
32、l jLabel2 = new JLabel();JLabel jLabel3 = new JLabel();JLabel jLabel4 = new JLabel();JLabel jLabel5 = new JLabel();JTextField sid = new JTextField(10);JTextField sname = new JTextField(10);JTextField sowner = new JTextField(10);JTextField sstatus = new JTextField(10);JTextField suser = new JTextFiel
33、d(10);JButton editconfirm = new JButton();public bookEdit()this.setTitle(修改图书信息);this.setResizable(false);tryInit();catch (Exception e)e.printStackTrace();/设置居中Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height -
34、 300)/2 +45);public void Init() throws Exceptionthis.setSize(300,500);c = this.getContentPane();c.setLayout(new FlowLayout();jLabel1.setText(要修改的图书ID: );jLabel1.setFont(new Font(Dialog,0,12);c.add(jLabel1);sid.setText(null);sid.setFont(new Font(Dialog,0,12);c.add(sid);jLabel2.setText(图书名称: );jLabel2
35、.setFont(new Font(Dialog,0,12);c.add(jLabel2);sname.setText(null);sname.setFont(new Font(Dialog,0,12);c.add(sname);jLabel3.setText(图书所有者: );jLabel3.setFont(new Font(Dialog,0,12);c.add(jLabel3);sowner.setText(null);sowner.setFont(new Font(Dialog,0,12);c.add(sowner);editconfirm.setText(确认修改);editconfi
36、rm.setFont(new Font(Dialog,0,12);c.add(editconfirm);editconfirm.addActionListener(this);public void actionPerformed(ActionEvent e)Object obj = e.getSource();if(obj = editconfirm)bookBean rs = new bookBean();rs.bookModify(sid.getText(),sname.getText(),sowner.getText();this.dispose();bookDel.javapacka
37、ge bookDB;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class bookDel extends JFrame implements ActionListenerContainer c;JLabel jLabel1 = new JLabel();JTextField sid = new JTextField(10);JButton delconfirm = new JButton();public bookDel()this.setTitle(删除图书信息);this.setResizab
38、le(false);tryInit();catch (Exception e)e.printStackTrace();/设置居中Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height - 300)/2 +45);public void Init() throws Exceptionthis.setSize(300,500);c = this.getContentPane();
39、c.setLayout(new FlowLayout();jLabel1.setText(要删除的图书ID: );jLabel1.setFont(new Font(Dialog,0,12);c.add(jLabel1);sid.setText(null);sid.setFont(new Font(Dialog,0,12);c.add(sid);delconfirm.setText(确认删除);delconfirm.setFont(new Font(Dialog,0,12);c.add(delconfirm);delconfirm.addActionListener(this);public v
40、oid actionPerformed(ActionEvent e)Object obj = e.getSource();if(obj = delconfirm)bookBean rs = new bookBean();rs.bookDel(sid.getText();this.dispose();bookDisplay.javapackage bookDB;import java.awt.*;import javax.swing.*;public class bookDisplay extends JFrameJLabel jLabel1 = new JLabel();JButton jBE
41、xit = new JButton();JScrollPane jScrollPane1;JTable jTabstuInfo;String sNum;String 列名 = 图书ID,图书名,图书所有者,图书状态,使用者;String 列值;String sColValue;String sColName;String sFromValue;String sToValue;public bookDisplay()this.setTitle(学生信息查询结果);/-设置运行位置居中-Dimension screenSize = Toolkit.getDefaultToolkit().getSc
42、reenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height - 300)/2 +45);bookBean rstu = new bookBean();try列值 = rstu.bookAllSearch();if(列值 = null)JOptionPane.showMessageDialog(null, 没有符合条件的记录);this.dispose();elsejTabstuInfo = new JTable(列值,列名);jScrollPane1 = new JScrollPane(j
43、TabstuInfo);this.getContentPane().add(jScrollPane1,BorderLayout.CENTER);this.pack();this.setVisible(true);catch (Exception e) e.printStackTrace();bookBook.javapackage bookDB;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class bookBook extends JFrame implements ActionListenerC
44、ontainer c;JLabel jLabel1 = new JLabel();JLabel jLabel2 = new JLabel();JTextField sname = new JTextField(10);JTextField suser = new JTextField(10);JButton bookconfirm = new JButton();public bookBook()this.setTitle(借阅图书);this.setResizable(false);tryInit();catch (Exception e)e.printStackTrace();/设置居中D
45、imension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height - 300)/2 +45);public void Init() throws Exceptionthis.setSize(300,500);c = this.getContentPane();c.setLayout(new FlowLayout();jLabel1.setText(借阅图书名称: );jLabel1.se
46、tFont(new Font(Dialog,0,12);c.add(jLabel1);sname.setText(null);sname.setFont(new Font(Dialog,0,12);c.add(sname);jLabel2.setText(借阅者姓名: );jLabel2.setFont(new Font(Dialog,0,12);c.add(jLabel2);suser.setText(null);suser.setFont(new Font(Dialog,0,12);c.add(suser);bookconfirm.setText(确定);bookconfirm.setFo
47、nt(new Font(Dialog,0,12);c.add(bookconfirm);bookconfirm.addActionListener(this);public void actionPerformed(ActionEvent e)Object obj = e.getSource();if(obj = bookconfirm)bookBean rs = new bookBean();rs.bookBook(sname.getText(),suser.getText();this.dispose();bookReturn.javapackage bookDB;import java.
48、awt.*;import java.awt.event.*;import javax.swing.*;public class bookReturn extends JFrame implements ActionListenerContainer c;JLabel jLabel1 = new JLabel();JTextField sname = new JTextField(10);JButton reconfirm = new JButton();public bookReturn()this.setTitle(归还图书);this.setResizable(false);tryInit
49、();catch (Exception e)e.printStackTrace();/设置居中Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height - 300)/2 +45);public void Init() throws Exceptionthis.setSize(300,500);c = this.getContentPane();c.setLayout(new F
50、lowLayout();jLabel1.setText(归还图书名称: );jLabel1.setFont(new Font(Dialog,0,12);c.add(jLabel1);sname.setText(null);sname.setFont(new Font(Dialog,0,12);c.add(sname);reconfirm.setText(确定);reconfirm.setFont(new Font(Dialog,0,12);c.add(reconfirm);reconfirm.addActionListener(this);public void actionPerformed(A
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论