?? login.java
字號:
package main;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JComboBox;
import java.awt.Font;
import java.sql.ResultSet;
import main.StartClass;
import purchase.Purchase;
import depot.Depot;
import main.DataBase;
import reception.Reception;
public class LogIn extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JButton confirm = null;
private JButton cancel = null;
private JTextField username = null;
private JPasswordField passWord = null;
private JComboBox type = null;
/**
* This method initializes confirm
*
* @return javax.swing.JButton
*/
private JButton getConfirm() {
if (confirm == null) {
confirm = new JButton();
confirm.setBounds(new Rectangle(40, 174, 102, 47));
confirm.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
confirm.setText("確認(rèn)");
confirm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//System.out.println("hi");
String username=LogIn.this.getUsername().getText();
String password=new String(LogIn.this.getPassWord().getPassword());
String type=(String)LogIn.this.getType().getSelectedItem();
//System.out.println(username+" "+password+" "+type);
String sql;
String table;
if(type.equals("會員")){
table="member";
}else{
table="staff";
}
sql="select * from "
+table+" where ID_Number='"+username+
"'"+" and password='"+password+"'";
String job=" and job='"+type+"'";
if(!type.equals("會員"))
sql+=job;
System.out.println(sql);
ResultSet result=DataBase.executeQuery(sql);
if(DataBase.exist(result)){
//System.out.println("there exists");
StartClass.username=username;
StartClass.password=password;
StartClass.type=type;
LogIn.this.logIn(type);
}else{
//System.out.println("there not exists");
javax.swing.JOptionPane.showMessageDialog(null,"圖書館管理系統(tǒng)\n"+
"用戶信息錯(cuò)誤!!!!");
}
}
});
}
return confirm;
}
/**
* This method initializes cancel
*
* @return javax.swing.JButton
*/
private JButton getCancel() {
if (cancel == null) {
cancel = new JButton();
cancel.setBounds(new Rectangle(157, 174, 102, 47));
cancel.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
cancel.setText("取消");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//System.out.println("hhi");
System.exit(0);
}
});
}
return cancel;
}
/**
* This method initializes username
*
* @return javax.swing.JTextField
*/
private JTextField getUsername() {
if (username == null) {
username = new JTextField();
username.setBounds(new Rectangle(101, 37, 162, 29));
}
return username;
}
/**
* This method initializes passWord
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getPassWord() {
if (passWord == null) {
passWord = new JPasswordField();
passWord.setBounds(new Rectangle(102, 70, 162, 29));
}
return passWord;
}
/**
* This method initializes type
*
* @return javax.swing.JComboBox
*/
private JComboBox getType() {
if (type == null) {
type = new JComboBox();
type.setBounds(new Rectangle(103, 105, 160, 25));
type.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
type.addItem("會員");
type.addItem("借閱臺");
type.addItem("倉庫");
type.addItem("采購");
//type.addItem("館長");
}
return type;
}
/**
* This is the default constructor
*/
public LogIn() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(293, 287);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getJContentPane());
this.setTitle("登陸對話框");
this.setVisible(true);
this.setLocation(250,250);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(24, 106, 65, 27));
jLabel2.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
jLabel2.setText("身份");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(24, 71, 65, 27));
jLabel1.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
jLabel1.setText("密碼");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(24, 37, 65, 27));
jLabel.setFont(new Font("\u6977\u4f53_GB2312", Font.BOLD, 18));
jLabel.setText("用戶名");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getConfirm(), null);
jContentPane.add(getCancel(), null);
jContentPane.add(getUsername(), null);
jContentPane.add(getPassWord(), null);
jContentPane.add(getType(), null);
}
return jContentPane;
}
private void logIn(String type){
this.dispose();
if(type.equals("采購")){
//System.out.println("caigou");
new Purchase();
}else if(type.equals("倉庫")){
new Depot();
}else if(type.equals("館長")){
}else if(type.equals("借閱臺")){
new Reception();
}else{
new member.Member();
}
}
} // @jve:decl-index=0:visual-constraint="10,10"
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -