Java图书管理系统附源码.doc

上传人:牧羊曲112 文档编号:4219780 上传时间:2023-04-10 格式:DOC 页数:28 大小:479KB
返回 下载 相关 举报
Java图书管理系统附源码.doc_第1页
第1页 / 共28页
Java图书管理系统附源码.doc_第2页
第2页 / 共28页
Java图书管理系统附源码.doc_第3页
第3页 / 共28页
Java图书管理系统附源码.doc_第4页
第4页 / 共28页
Java图书管理系统附源码.doc_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《Java图书管理系统附源码.doc》由会员分享,可在线阅读,更多相关《Java图书管理系统附源码.doc(28页珍藏版)》请在三一办公上搜索。

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.getMessage();publ

12、ic 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 java.awt.

13、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.swing.JMen

14、uBar;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 menubook =

15、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 itemDisplay =

16、 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.printStackTrace()

17、; 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(图书流通管理); me

18、nuevent.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.setFont(new

19、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(Dialog,0,12);

20、 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); this.setJMe

21、nuBar(mainMenu); /添加事件监听 itemExit.addActionListener(this); itemAdd.addActionListener(this); itemEdit.addActionListener(this); itemDelete.addActionListener(this); itemSelect.addActionListener(this); itemBook.addActionListener(this); itemReturn.addActionListener(this); itemDisplay.addActionListener(th

22、is); 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.downInit(); a

23、si.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 bookSea

24、rch(); 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(); sre.pa

25、ck(); 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 JLabel(

26、);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 addconfir

27、m = 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);public void

28、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(Dialog,0,12

29、);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(Dialog,0,12

30、);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 bookInfo Stri

31、ng 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();JLabel jLabel

32、2 = 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 JTextField(10);JB

33、utton 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 - 300)/2

34、+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.setFont

35、(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(确认修改);editconfirm.setFo

36、nt(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.javapackage bookD

37、B;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.setResizable(false

38、);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();c.setLay

39、out(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 void acti

40、onPerformed(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 jBExit = ne

41、w 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().getScreenSize();this.setLocation(int)(screenSize.width - 400)/2,(int)(screenSize.height - 300)/2 +45);bookBean rstu = new bookBean();try列值 = rstu.bookAllSearch();if(列值 =

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号