您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > Java编写的简单图书管理系统
Java编写的简单图书管理系统主界面代码实现packageLibrary;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JPasswordField;importjavax.swing.JTextField;publicclassLoginextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJLabeljlUsername;privateJLabeljlPwd;privateJTextFieldtxtUsername;//用户名privateJTextFieldtxtPassword;//密码privateJButtonjbOk;privateJButtonjbCancel;publicJLabelgetJlUsername(){if(jlUsername==null){jlUsername=newJLabel(账号);jlUsername.setForeground(Color.BLACK);jlUsername.setBounds(118,40,85,30);}returnjlUsername;}publicJLabelgetJlPwd(){if(jlPwd==null){jlPwd=newJLabel(密码);jlPwd.setForeground(Color.BLACK);jlPwd.setBounds(118,100,85,30);}returnjlPwd;}publicJTextFieldgetTxtUsername(){if(txtUsername==null){txtUsername=newJTextField(20);txtUsername.setBounds(180,40,200,30);}returntxtUsername;}publicJTextFieldgetTxtPassword(){if(txtPassword==null){txtPassword=newJPasswordField(20);txtPassword.setBounds(180,100,200,30);}returntxtPassword;}publicJButtongetJbOk(){if(jbOk==null){jbOk=newJButton(登陆);jbOk.setBounds(150,180,90,30);//jbOk.addActionListener(this);}returnjbOk;}publicJButtongetJbCancel(){if(jbCancel==null){jbCancel=newJButton(取消);jbCancel.setBounds(300,180,90,30);}returnjbCancel;}publicLogin(Stringtitle){super(title);//JFrameframe=newJFrame();Containercantainer=this.getContentPane();this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);ImageIconimg=newImageIcon(F:\\Java\\传习\\src\\Library\\ZF`XY`H48I_}U)C4~}M2~C4.jpg);//这是背景图片JLabelimgLabel=newJLabel(img);//将背景图放在标签里。this.getLayeredPane().add(imgLabel,newInteger(Integer.MIN_VALUE));//注意这里是关键,将背景标签添加到jfram的LayeredPane面板里。imgLabel.setBounds(0,0,img.getIconWidth(),img.getIconHeight());//设置背景标签的位置cantainer.setLayout(newBorderLayout());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);((JPanel)cantainer).setOpaque(false);//注意这里,将内容面板设为透明。这样LayeredPane面板中的背景才能显示出来。this.setSize(img.getIconWidth(),img.getIconHeight());myEvent();this.setVisible(true);this.setResizable(true);}privatevoidmyEvent(){jbCancel.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){Login.this.dispose();}});jbOk.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){Connectionconn=null;Statementstm=null;ResultSetst=null;try{Class.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql://localhost:3306/library,sa,123456);stm=conn.createStatement();Stringsql=select*fromuser;//Stringsql1=selectpswfromuser;st=stm.executeQuery(sql);//st1=stm.executeQuery(sql1);if(st.next()){if(txtUsername.getText().equals(st.getString(id))&&txtPassword.getText().equals(st.getString(psw))){Login.this.setVisible(false);newBook(管理界面);}else{JOptionPane.showMessageDialog(null,您输入的账号或密码不正确);getTxtUsername().setText();getTxtPassword().setText();}}else{JOptionPane.showMessageDialog(null,用户名不存在,请重新输入,错误!);getTxtUsername().setText();getTxtPassword().setText();}}catch(ClassNotFoundExceptione1){e1.printStackTrace();}catch(SQLExceptione2){//TODOAuto-generatedcatchblocke2.printStackTrace();}finally{try{stm.close();}catch(Exceptione3){}//关闭Connectiontry{conn.close();}catch(Exceptione4){}}}});}publicstaticvoidmain(String[]args){newLogin(图书管理登陆界面);}}管理界面实现代码packageLibrary;importjava.awt.BorderLayout;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTable;importjavax.swing.JTextField;publicclassBookextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJLabellblId;privateJLabellblBname;privateJLabellblWname;privateJLabellblCbs;privateJLabellblnum1;privateJLabellblnum2;privateJTextFieldbId;//图书编号privateJTextFieldbname;//书名privateJTextFieldwname;//作者名privateJTextFieldcbs;//出版社privateJTextFieldnum1;//现存量privateJTextFieldnum2;//库存量privateJButtonjbDel;privateJTextFieldjDel;privateJButtonjbAdd;privateJButtonjbSearch;privateJButtonjbUpdate;privateJTabletable;privateJLabeljabel;//输入要查找的书号publicJLabelgetJabel(){if(jabel==null){jabel=newJLabel(查删学号);jabel.setBounds(50,350,50,30);}returnjabel;}publicJButtongetJbDel(){if(jbDel==null){jbDel=newJButton(删除);jbDel.setBounds(180,400,60,30);}returnjbDel;}publicJTextFieldgetjDel(){if(jDel==null){jDel=newJTextField(20);jDel.setBound
本文标题:Java编写的简单图书管理系统
链接地址:https://www.777doc.com/doc-5826225 .html