收藏 分享(赏)

简单的java图书馆管理系统.doc

上传人:精品资料 文档编号:8822192 上传时间:2019-07-13 格式:DOC 页数:21 大小:658KB
下载 相关 举报
简单的java图书馆管理系统.doc_第1页
第1页 / 共21页
简单的java图书馆管理系统.doc_第2页
第2页 / 共21页
简单的java图书馆管理系统.doc_第3页
第3页 / 共21页
简单的java图书馆管理系统.doc_第4页
第4页 / 共21页
简单的java图书馆管理系统.doc_第5页
第5页 / 共21页
点击查看更多>>
资源描述

1、课程设计题目图书馆管理系统一、 设计环境DBMS:mysql开发工具:eclipse应用程序开发环境:win8.1系统运行环境: win8.1二、 概要设计(1)功能:1.创建图书馆界面(凭账号密码登陆)2.对数据库进行图书的查找、修改、添加、删除3.实时显示图书馆数据的改变(2)ER 图(3)流程图(4)表(5)数据(6)连接数据库代码Connection conn=null;Class.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3306/test“,“ro

2、ot“,“panda1993“);4、详细设计(1)主界面 Login.javaimport java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;

3、import java.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Login extends JFrame private sta

4、tic final long serialVersionUID = 1L;/保持兼容private JLabel jlUsername;private JLabel jlPwd;private JTextField txtUsername; /用户名private JTextField txtPassword; /密码private JButton jbOk;private JButton jbCancel;public JLabel getJlUsername() if(jlUsername=null)jlUsername=new JLabel(“账号“);jlUsername.setFor

5、eground(Color.black);jlUsername.setBounds(118, 40, 85, 30);return jlUsername;public JLabel getJlPwd() if(jlPwd=null)jlPwd=new JLabel(“密码“);jlPwd.setForeground(Color.LIGHT_GRAY);jlPwd.setBounds(118, 100, 85, 30);return jlPwd;public JTextField getTxtUsername() if(txtUsername=null)txtUsername=new JText

6、Field(20);txtUsername.setBounds(180,40 , 200, 30);return txtUsername;public JTextField getTxtPassword() if(txtPassword=null)txtPassword=new JPasswordField(20);txtPassword.setBounds(180, 100, 200, 30);return txtPassword;public JButton getJbOk() if(jbOk=null)jbOk=new JButton(“登陆“);jbOk.setBounds(150,

7、180, 90, 30);/jbOk.addActionListener(this);return jbOk;public JButton getJbCancel() if(jbCancel=null)jbCancel=new JButton(“取消“);jbCancel.setBounds(300, 180, 90, 30);return jbCancel;public Login(String title)super(title);/JFrame frame=new JFrame();Container cantainer =this.getContentPane();this.setDe

8、faultCloseOperation(JFrame.EXIT_ON_CLOSE);ImageIcon img = new ImageIcon(“C:UsersZpandaDesktopwebbookStoreimages1.jpg“);JLabel imgLabel = new JLabel(img);this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE);/将背景标签添加到 jfram 的 LayeredPane 面板里。imgLabel.setBounds(0,0,img.getIconWidth(), img

9、.getIconHeight();cantainer.setLayout(new BorderLayout();imgLabel.setLayout(null);imgLabel.add(getJlUsername();imgLabel.add(getTxtUsername();imgLabel.add(getJlPwd();imgLabel.add(getTxtPassword();imgLabel.add(getJbOk();imgLabel.add(getJbCancel();cantainer.add(imgLabel,BorderLayout.NORTH);/设置在框架北边(JPan

10、el)cantainer).setOpaque(false); /将内容面板设为透明this.setSize(img.getIconWidth(),img.getIconHeight();myEvent();this.setVisible(true);this.setResizable(false);/让窗口和图 片一样大小private void myEvent()jbCancel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Login.this.dispose(););jbO

11、k.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection conn=null;Statement stm=null;ResultSet st=null;tryClass.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3306/test“,“root“,“panda1993“);stm=conn.createStatement();Stri

12、ng sql=“select * from user“;/String sql1=“select psw from user“;st=stm.executeQuery(sql);/ st1=stm.executeQuery(sql1);if(st.next()if(txtUsername.getText().equals(st.getString(“id“)new Book(“管理界面 “);elseJOptionPane.showMessageDialog(null, “您输入的账号或密码不正确“);getTxtUsername().setText(“);getTxtPassword().s

13、etText(“);elseJOptionPane.showMessageDialog(null,“用户名不存在, 请重新输入,错误!“);getTxtUsername().setText(“);getTxtPassword().setText(“);catch(ClassNotFoundException e1)e1.printStackTrace(); catch (SQLException e2) / TODO Auto-generated catch blocke2.printStackTrace();finallytrystm.close();catch (Exception e3)

14、 / 关闭 Connection try conn.close(); catch (Exception e4) );public static void main(String args)new Login(“图书管理登陆界面“);(2)管理界面 Book.javaimport java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionLi

15、stener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.AbstractButton;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JFrame;import ja

16、vax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.table.TableCellRenderer;public class Book extends JFrame private static final long serialVersionUID = 1L;private JLabel

17、lblId;private JLabel lblBname;private JLabel lblWname;private JLabel lblCbs;private JLabel lblnum1;private JLabel lblnum2;private JTextField bId; /图书编号private JTextField bname; /书名private JTextField wname; /作者名private JTextField cbs; /出版社private JTextField num1; /现存量private JTextField num2; /库存量priv

18、ate JButton jbDel;private JTextField jDel;private JButton jbAdd;private JButton jbSearch;private JButton jbUpdate;private JTable table;/数据库表private JLabel jabel;/输入要查找的书号private JScrollPane scpDemo;private Object btnShow;SuppressWarnings(“unused“)private Object jth;public JLabel getJabel() if(jabel=

19、null)jabel=new JLabel(“查删编号“);jabel.setForeground(Color.red);jabel.setBounds(450, 350, 60, 30);return jabel;public JButton getJbDel() if(jbDel=null)jbDel=new JButton(“删除“);jbDel.setBounds(580, 400, 60, 30);return jbDel;public JTextField getjDel() if(jDel=null)jDel=new JTextField(20);jDel.setBounds(5

20、00, 350, 150, 30);return jDel;public JButton getJbAdd() if(jbAdd=null)jbAdd=new JButton(“添加“);jbAdd.setBounds(500,400,60,30);return jbAdd;public JButton getJbSearch() if(jbSearch=null)jbSearch=new JButton(“查找“);jbSearch.setBounds(500, 450, 60, 30);return jbSearch;public JButton getJbUpdate() if(jbUp

21、date=null)jbUpdate=new JButton(“修改“);jbUpdate.setBounds(580, 450, 60, 30);return jbUpdate;SuppressWarnings(“serial“)public JTable getTable() JTable table = new JTable(20,3) /设 置 JTable 的单元格为透明的public Component prepareRenderer(TableCellRenderer renderer,int row,int column)Component c=super.prepareRen

22、derer(renderer,row,column);if(c instanceof JComponent)(JComponent)c).setOpaque(false);return c;table.setOpaque(false);/设置 jtable 本身为透明的this.setSize(450, 400);this.setLayout(null);this.setLocation(270, 50);this.scpDemo = new JScrollPane();this.scpDemo.setBounds(10, 100, 420, 270);this.scpDemo.setOpaq

23、ue(false); /透明this.scpDemo.getViewport().setOpaque(false);/透明this.btnShow = new JButton(“显示数据(刷新)“);(Component) this.btnShow).setBounds(10, 50, 420, 30);(AbstractButton) this.btnShow).addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) btnShow_ActionPerformed(ae););add

24、(this.scpDemo);add(Component) this.btnShow);this.setVisible(true);return table;public void btnShow_ActionPerformed(ActionEvent ae) Connection conn=null;try Class.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3306/test“,“root“,“panda1993“);Statement pstm = c

25、onn.createStatement();String sql1 = “select count(*) from Book“; String sql2 = “select * from Book“;ResultSet rs1 = pstm.executeQuery(sql1);int count = 0;/得到总记录数if (rs1.next() count=rs1.getInt(1);/关闭第一个结果集rs1.close();Object info = new Objectcount6;count = 0;/查询ResultSet rs2 = pstm.executeQuery(sql2)

26、;while (rs2.next() infocount0 = rs2.getString(“Bid“);infocount1 = rs2.getString(“Bname“);infocount2 = rs2.getString(“Wname“);infocount3 = rs2.getString(“num1“);infocount4 = rs2.getString(“num2“);infocount5 = rs2.getString(“chubs“);count+;for(Object o:info)System.out.println(o0);System.out.println(o1

27、);System.out.println(o2);System.out.println(o3);System.out.println(o4);String title = “编号“ , “书名“, “作者“, “现存量“, “库存量“, “出版社“;/ 创建 JTablethis.table = new JTable(info, title);/ 显示表头this.jth = this.table.getTableHeader();/ 将 JTable 加入到 带滚动条的面板中this.scpDemo.getViewport().add(table); catch (Exception sql

28、e) JOptionPane.showMessageDialog(null, “错误:“+sqle.getMessage(), “错误“ ,JOptionPane.ERROR_MESSAGE);public JLabel getLblId() if(lblId=null)lblId=new JLabel(“编号“);lblId.setForeground(Color.red);lblId.setBounds(450, 50, 50, 30);return lblId;public JLabel getLblBname() if(lblBname=null)lblBname=new JLabel

29、(“书名“);lblBname.setForeground(Color.red);lblBname.setBounds(450, 100, 50, 30);return lblBname;public JLabel getLblWname() if(lblWname=null)lblWname=new JLabel(“作者“);lblWname.setForeground(Color.red);lblWname.setBounds(450,150, 50, 30);return lblWname;public JLabel getLblnum1() if(lblnum1=null)lblnum

30、1=new JLabel(“现存量“ );lblnum1.setForeground(Color.red);lblnum1.setBounds(450,200, 50, 30);return lblnum1;public JLabel getLblnum2() if(lblnum2=null)lblnum2=new JLabel(“库存量“ );lblnum2.setForeground(Color.red);lblnum2.setBounds(450,250, 50, 30);return lblnum2;public JTextField getbId() if(bId=null)bId=

31、new JTextField(20);bId.setBounds(500, 50,150, 30);return bId;public JTextField getBname() if(bname=null)bname=new JTextField(20);bname.setBounds(500, 100, 150, 30);return bname;public JTextField getWname() if(wname=null)wname=new JTextField(20);wname.setBounds(500, 150, 150, 30);return wname;public

32、JTextField getNum1() if(num1=null)num1=new JTextField(20);num1.setBounds(500, 200, 150, 30);return num1;public JTextField getNum2() if(num2=null)num2=new JTextField(20);num2.setBounds(500, 250, 150, 30);return num2;public JLabel getLblCbs() if(lblCbs=null)lblCbs=new JLabel(“出版社“);lblCbs.setForegroun

33、d(Color.red);lblCbs.setBounds(450,300, 50, 30);return lblCbs;public JTextField getCbs() if(cbs=null)cbs=new JTextField(20);cbs.setBounds(500, 300, 150, 30);return cbs;public Book(String title)super(title);/JFrame frame=new JFrame();Container cantainer=this.getContentPane();this.setDefaultCloseOperat

34、ion(JFrame.EXIT_ON_CLOSE);ImageIcon img = new ImageIcon(“C:UsersZpandaDesktopwebbookStoreimages3.jpg“);/这是背景图片JLabel imgLabel = new JLabel(img);/将背景图放在标签里。this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE);/将背景标签添加到 jfram 的 LayeredPane 面板里。imgLabel.setBounds(0,0,img.getIconWidth(), i

35、mg.getIconHeight();/设置背景标签的位置cantainer.setLayout(new BorderLayout();imgLabel.setLayout(null);imgLabel.add(getLblId();imgLabel.add(getbId();imgLabel.add(getLblBname();imgLabel.add(getBname();imgLabel.add(getLblWname();imgLabel.add(getWname();imgLabel.add(getLblnum1();imgLabel.add(getNum1();imgLabel.a

36、dd(getLblnum2();imgLabel.add(getNum2();imgLabel.add(getLblCbs();imgLabel.add(getCbs();imgLabel.add(getTable();imgLabel.add(getJbDel();imgLabel.add(getjDel();imgLabel.add(getJbAdd();imgLabel.add(getJbSearch();imgLabel.add(getJbUpdate();imgLabel.add(getJabel();cantainer.add(imgLabel,BorderLayout.NORTH

37、);(JPanel)cantainer).setOpaque(false); /将内容面板设为透明this.setSize(img.getIconWidth(),img.getIconHeight();myEvent();this.setVisible(true);this.setResizable(false);private void myEvent() / TODO Auto-generated method stubjbAdd.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ee

38、)Connection conn=null;Statement stm=null;String id1=bId.getText();String name1=bname.getText();String name2=wname.getText();String n1=num1.getText();String n2=num2.getText();String chubs=cbs.getText();tryClass.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3

39、306/test“,“root“,“panda1993“);stm=conn.createStatement();String sql=“insert into Book values(“+id1+“,“+name1+“,“+name2+“,“+n1+“,“+n2+“,“+chubs+“)“;stm.executeUpdate(sql);/connection 数据库链接对 象 创建一个 statement对象数据 库操作对象getbId().setText(“);getBname().setText(“);getWname().setText(“);getNum1().setText(“);

40、getNum2().setText(“);getCbs().setText(“);catch(ClassNotFoundException e) catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finally / 关闭 Statement try stm.close(); catch (Exception e) / 关闭 Connection try conn.close(); catch (Exception e) );jbDel.addActionListener(new ActionL

41、istener()public void actionPerformed(ActionEvent ee)String id=jDel.getText();Connection conn=null;Statement stm=null;tryClass.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3306/test“,“root“,“panda1993“);/String sql=“select * from book“;String sql=“delete fr

42、om Book where Bid=“+id+“;stm=conn.createStatement();stm.executeUpdate(sql);getjDel().setText(“);catch(ClassNotFoundException e) catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finally / 关闭 Statement try stm.close(); catch (Exception e) / 关闭 Connection try conn.close(); ca

43、tch (Exception e) );jbSearch.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ee)String id=jDel.getText();Connection conn=null;Statement stm=null;ResultSet rst=null;tryClass.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3306/tes

44、t“,“root“,“panda1993“);/String sql=“select * from book“;String sql=“select * from Book where Bid=“+id+“;stm=conn.createStatement();rst=stm.executeQuery(sql);if(rst.next()getbId().setText(rst.getString(“Bid“);getBname().setText(rst.getString(“Bname“);getWname().setText(rst.getString(“Wname“);getNum1(

45、).setText(rst.getString(“num1“);getNum2().setText(rst.getString(“num2“);getCbs().setText(rst.getString(“chubs“);getjDel().setText(“);catch(ClassNotFoundException e) catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finally / 关闭 Statement try stm.close(); catch (Exception e)

46、 / 关闭 Connection try conn.close(); catch (Exception e) );jbUpdate.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ee)String id1=bId.getText();String name1=bname.getText();String name2=wname.getText();String n1=num1.getText();String n2=num2.getText();String chubs=cbs.get

47、Text();Connection conn=null;Statement stm=null;tryClass.forName(“com.mysql.jdbc.Driver“);conn=DriverManager.getConnection(“jdbc:mysql:/localhost:3306/test“,“root“,“panda1993“);String sql=“update test.Book set Bname=“+name1+“,Wname=“+name2+“,num1=“+n1+“,num2=“+n2+“,chubs=“+chubs+“ where Bid=“+id1+“;s

48、tm=conn.createStatement();stm.executeUpdate(sql);catch(ClassNotFoundException e) catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finally / 关闭 Statement try stm.close(); catch (Exception e) / 关闭 Connection try conn.close(); catch (Exception e) ); 5、收获体会本次图书馆管理系统基本操作完成,但有很多不足,数据库表太少,操作不够人性化,功能略显简陋。但是通过这次数据库的课设,让我加深对数据库与外界交流的理解,特别是如何动态

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

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报