?? login.java~39~
字號:
package zcgl;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Login extends JFrame {
Connection con = null;
Statement smt = null;
ResultSet rs = null;
public Login() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel1.setText("用戶名");
jLabel1.setBounds(new Rectangle(97, 90, 82, 40));
jButton1.setBounds(new Rectangle(110, 211, 112, 37));
jButton1.setText("登陸");
jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
txtPass.setBounds(new Rectangle(162, 154, 133, 22));
jButton2.setBounds(new Rectangle(232, 212, 112, 37));
jButton2.setText("退出");
jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
jLabel2.setText("密碼");
jLabel2.setBounds(new Rectangle(99, 149, 51, 30));
this.getContentPane().add(txtPass);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(jLabel1);
this.getContentPane().add(txtName);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton1);
txtName.setBounds(new Rectangle(162, 98, 131, 27));
}
JLabel jLabel1 = new JLabel();
JTextField txtName = new JTextField();
JLabel jLabel2 = new JLabel();
JButton jButton1 = new JButton();
JPasswordField txtPass = new JPasswordField();
JButton jButton2 = new JButton();
public void jButton1_actionPerformed(ActionEvent e) {
con = new DbCon().getConnection();
try {
smt = con.createStatement();
rs = smt.executeQuery("select * from OPERATOR");
if (rs.next()) {
String name = rs.getString(1).trim();
String pass = rs.getString(2).trim();
if (txtName.getText().equals(name) &&
String.copyValueOf(txtPass.getPassword()).equals(pass)) {
MainFrame frame = new MainFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) /
2);
frame.setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "用戶名或密碼錯誤!");
return;
}
}
} catch (SQLException ex) {
}
}
public void jButton2_actionPerformed(ActionEvent e) {
dispose();
}
}
class Login_jButton2_actionAdapter implements ActionListener {
private Login adaptee;
Login_jButton2_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Login_jButton1_actionAdapter implements ActionListener {
private Login adaptee;
Login_jButton1_actionAdapter(Login adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -