Java编写的简单图书管理系统(1).doc
《Java编写的简单图书管理系统(1).doc》由会员分享,可在线阅读,更多相关《Java编写的简单图书管理系统(1).doc(73页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateJava编写的简单图书管理系统(1)Java编写的简单图书管理系统Java编写的简单图书管理系统主界面代码实现package Library;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;imp
2、ort 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.J
3、OptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Login extends JFrame private static final long serialVersionUID = 1L;private JLabel jlUsername;private JLabel jlPwd;private JTextField txtUsername; /用户名private JTextField txtPassword; /密
4、码private JButton jbOk;private JButton jbCancel;public JLabel getJlUsername() if(jlUsername=null)jlUsername=new JLabel(账号);jlUsername.setForeground(Color.BLACK);jlUsername.setBounds(118, 40, 85, 30);return jlUsername;public JLabel getJlPwd() if(jlPwd=null)jlPwd=new JLabel(密码);jlPwd.setForeground(Colo
5、r.BLACK);jlPwd.setBounds(118, 100, 85, 30);return jlPwd;public JTextField getTxtUsername() if(txtUsername=null)txtUsername=new JTextField(20);txtUsername.setBounds(180,40 , 200, 30);return txtUsername;public JTextField getTxtPassword() if(txtPassword=null)txtPassword=new JPasswordField(20);txtPasswo
6、rd.setBounds(180, 100, 200, 30);return txtPassword;public JButton getJbOk() if(jbOk=null)jbOk=new JButton(登陆);jbOk.setBounds(150, 180, 90, 30);/jbOk.addActionListener(this);return jbOk;public JButton getJbCancel() if(jbCancel=null)jbCancel=new JButton(取消);jbCancel.setBounds(300, 180, 90, 30);return
7、jbCancel;public Login(String title)super(title);/JFrame frame=new JFrame();Container cantainer=this.getContentPane();this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);ImageIcon img = new ImageIcon(F:Java传习srcLibraryZFXYH48I_U)C4M2C4.jpg);/这是背景图片JLabel imgLabel = new JLabel(img);/将背景图放在标签里。this.get
8、LayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE);/注意这里是关键,将背景标签添加到jfram的LayeredPane面板里。imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight();/设置背景标签的位置cantainer.setLayout(new BorderLayout();imgLabel.setLayout(null);imgLabel.add(getJlUsername();imgLabel.add(getTxtUsername();imgLabe
9、l.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(tru
10、e);this.setResizable(true);private void myEvent()jbCancel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Login.this.dispose(););jbOk.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection conn=null;Statement stm=null;ResultSet st=n
11、ull;tryClass.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/library,sa,123456);stm=conn.createStatement();String sql=select * from user;/String sql1=select psw from user;st=stm.executeQuery(sql);/ st1=stm.executeQuery(sql1);if(st.next()if(txtUsername.getTe
12、xt().equals(st.getString(id)&txtPassword.getText().equals(st.getString(psw)Login.this.setVisible(false);new Book(管理界面);elseJOptionPane.showMessageDialog(null, 您输入的账号或密码不正确);getTxtUsername().setText();getTxtPassword().setText();else JOptionPane.showMessageDialog(null,用户名不存在,请重新输入,错误!); getTxtUsername
13、().setText();getTxtPassword().setText();catch(ClassNotFoundException e1)e1.printStackTrace(); catch (SQLException e2) / TODO Auto-generated catch blocke2.printStackTrace();finallytrystm.close();catch (Exception e3) / 关闭Connection try conn.close(); catch (Exception e4) );public static void main(Strin
14、g args)new Login(图书管理登陆界面);管理界面实现代码package Library;import java.awt.BorderLayout;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;import java
15、.sql.Statement;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTable;import javax.swing.JTextField;public class Book extends JFrame private static final long serialVersionUID = 1L;private JLabel
16、 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; /库存量pri
17、vate JButton jbDel;private JTextField jDel;private JButton jbAdd;private JButton jbSearch;private JButton jbUpdate;private JTable table;private JLabel jabel;/输入要查找的书号public JLabel getJabel() if(jabel=null)jabel=new JLabel(查删学号);jabel.setBounds(50, 350, 50, 30);return jabel;public JButton getJbDel()
18、if(jbDel=null)jbDel=new JButton(删除);jbDel.setBounds(180, 400, 60, 30);return jbDel;public JTextField getjDel() if(jDel=null)jDel=new JTextField(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;
19、public JButton getJbSearch() if(jbSearch=null)jbSearch=new JButton(查找);jbSearch.setBounds(100, 450, 60, 30);return jbSearch;public JButton getJbUpdate() if(jbUpdate=null)jbUpdate=new JButton(修改);jbUpdate.setBounds(180, 450, 60, 30);return jbUpdate;public JTable getTable() if(table=null)table=new JTa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 编写 简单 图书 管理 系统
限制150内