📄 library.java
字号:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class library extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jPanel = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JTextField jTextField = null;
private JPasswordField jPasswordField = null;
/**
* This is the default constructor
*/
public library() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJPanel());
this.setTitle("图书馆管理系统");
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(43, 59, 69, 22));
jLabel1.setText("密码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(43, 26, 69, 22));
jLabel.setText("用户名:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(getJButton(), null);
jPanel.add(getJButton1(), null);
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(getJTextField(), null);
jPanel.add(getJPasswordField(), null);
}
return jPanel;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(62, 124, 66, 24));
jButton.setText("登陆");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
jButton_ok(e);
}
});
}
return jButton;
}
public void jButton_ok(ActionEvent e){
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce)
{
System.out.println("SQLException:"+ce.getMessage());
}
try
{
Connection con =DriverManager.getConnection("jdbc:odbc:lib");
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery("select Name,Pass from User where Name='"+jTextField.getText()+"' and Pass='"+jPasswordField.getText()+"'");
if(!rs.next()){
JOptionPane.showMessageDialog(null, "登陆失败!");
}
else{
this.hide();
new book();
//JOptionPane.showMessageDialog(null, "登陆成功!");
}
//rs.close();
//stmt.close();
}
catch (SQLException ce)
{
System.out.println("SQLException:"+ce.getMessage());
}
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(167, 124, 71, 24));
jButton1.setText("取消");
}
return jButton1;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(122, 26, 103, 25));
}
return jTextField;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(122, 57, 103, 25));
}
return jPasswordField;
}
public static void main(){
new library();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -