Java编写的简单图书管理系统(共16页).doc
《Java编写的简单图书管理系统(共16页).doc》由会员分享,可在线阅读,更多相关《Java编写的简单图书管理系统(共16页).doc(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上Java编写的简单图书管理系统主界面代码实现package Library;import 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.SQ
2、LException;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
3、private static 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.se
4、tForeground(Color.BLACK);jlUsername.setBounds(118, 40, 85, 30);return jlUsername;public JLabel getJlPwd() if(jlPwd=null)jlPwd=new JLabel(密码);jlPwd.setForeground(Color.BLACK);jlPwd.setBounds(118, 100, 85, 30);return jlPwd;public JTextField getTxtUsername() if(txtUsername=null)txtUsername=new JTextFie
5、ld(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, 180,
6、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.setDefaultClo
7、seOperation(JFrame.EXIT_ON_CLOSE);ImageIcon img = new ImageIcon(F:Java传习srcLibraryZFXYH48I_U)C4M2C4.jpg);/这是背景图片JLabel imgLabel = new JLabel(img);/将背景图放在标签里。this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE);/注意这里是关键,将背景标签添加到jfram的LayeredPane面板里。imgLabel.setBounds(0,0,img.getIconWidt
8、h(), img.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.NO
9、RTH);(JPanel)cantainer).setOpaque(false); /注意这里,将内容面板设为透明。这样LayeredPane面板中的背景才能显示出来。this.setSize(img.getIconWidth(),img.getIconHeight();myEvent();this.setVisible(true);this.setResizable(true);private void myEvent()jbCancel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent
10、 e)Login.this.dispose(););jbOk.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/library,sa,);stm=conn.createSta
11、tement();String 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)&txtPassword.getText().equals(st.getString(psw)Login.this.setVisible(false);new Book(管理界面);elseJOptionPane.showMe
12、ssageDialog(null, 您输入的账号或密码不正确);getTxtUsername().setText();getTxtPassword().setText();else JOptionPane.showMessageDialog(null,用户名不存在,请重新输入,错误!); getTxtUsername().setText();getTxtPassword().setText();catch(ClassNotFoundException e1)e1.printStackTrace(); catch (SQLException e2) / TODO Auto-generated c
13、atch blocke2.printStackTrace();finallytrystm.close();catch (Exception e3) / 关闭Connection try conn.close(); catch (Exception e4) );public static void main(String args)new Login(图书管理登陆界面);管理界面实现代码package Library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.event.ActionEvent;i
14、mport java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing
15、.JPanel;import javax.swing.JTable;import javax.swing.JTextField;public class Book extends JFrame private static final long serialVersionUID = 1L;private JLabel lblId;private JLabel lblBname;private JLabel lblWname;private JLabel lblCbs;private JLabel lblnum1;private JLabel lblnum2;private JTextField
16、 bId; /图书编号private JTextField bname; /书名private JTextField wname; /作者名private JTextField cbs; /出版社private JTextField num1; /现存量private JTextField num2; /库存量private JButton jbDel;private JTextField jDel;private JButton jbAdd;private JButton jbSearch;private JButton jbUpdate;private JTable table;priva
17、te JLabel jabel;/输入要查找的书号public JLabel getJabel() if(jabel=null)jabel=new JLabel(查删学号);jabel.setBounds(50, 350, 50, 30);return jabel;public JButton getJbDel() if(jbDel=null)jbDel=new JButton(删除);jbDel.setBounds(180, 400, 60, 30);return jbDel;public JTextField getjDel() if(jDel=null)jDel=new JTextFie
18、ld(20);jDel.setBounds(100, 350, 150, 30);return jDel;public JButton getJbAdd() if(jbAdd=null)jbAdd=new JButton(添加);jbAdd.setBounds(100,400,60,30);return jbAdd;public JButton getJbSearch() if(jbSearch=null)jbSearch=new JButton(查找);jbSearch.setBounds(100, 450, 60, 30);return jbSearch;public JButton ge
19、tJbUpdate() if(jbUpdate=null)jbUpdate=new JButton(修改);jbUpdate.setBounds(180, 450, 60, 30);return jbUpdate;public JTable getTable() if(table=null)table=new JTable(100,6);table.setBounds(270, 50, 500, 600);return table;public JLabel getLblId() if(lblId=null)lblId=new JLabel(编号);lblId.setBounds(50, 50
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 编写 简单 图书 管理 系统 16
限制150内