?? loginpanel.java
字號:
package cn.javass.bookmgr.user.ui.panels;
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import java.awt.event.*;
import cn.javass.bookmgr.user.business.factory.UserFactory;
import cn.javass.bookmgr.MainFrame;
import cn.javass.bookmgr.user.valueobject.UserModel;
/**
* 用戶模塊表現層用于用戶登錄的Panel
*
* <p>Title: Java私塾第一個Java項目——圖書進銷存系統(單機版)</p>
* <p>Description: 網址:<a href="http://www.javass.cn">http://www.javass.cn</a>
* 新電話:010-86835215 新地址:北京市海淀區廠洼路5號院深博達商務樓5層</p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: Java私塾</p>
* @author Java私塾
* @version 1.0
*/
public class LoginPanel extends JPanel {
//以下為本界面需要的組件定義
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField txt_userId = new JTextField();
JPasswordField pwd_pwd = new JPasswordField();
JButton btn_login = new JButton();
/**
* 用來保持對主窗體的引用
*/
MainFrame mf= null;
/**
* 構建用戶登錄的Panel
* @param mf 主窗體的引用
*/
public LoginPanel(MainFrame mf) {
try {
this.mf = mf;
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
/**
* 真正進行組件初始化,并構建整個界面
* @throws Exception
*/
void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("SansSerif", 1, 30));
jLabel1.setText("歡迎使用Javass圖書進銷存(單機版)");
this.setLayout(xYLayout1);
this.setMinimumSize(new Dimension(800, 600));
this.setPreferredSize(new Dimension(800, 600));
xYLayout1.setWidth(800);
xYLayout1.setHeight(600);
jLabel2.setText("用戶編號");
jLabel3.setText("用戶口令");
txt_userId.setText("");
pwd_pwd.setText("");
btn_login.setText("登錄");
btn_login.addActionListener(new LoginPanel_btn_login_actionAdapter(this));
this.add(jLabel1, new XYConstraints(160, 40, 535, 76));
this.add(jLabel2, new XYConstraints(275, 152, 65, 37));
this.add(txt_userId, new XYConstraints(338, 155, 209, 34));
this.add(pwd_pwd, new XYConstraints(338, 218, 209, 34));
this.add(jLabel3, new XYConstraints(275, 215, 65, 37));
this.add(btn_login, new XYConstraints(456, 277, 91, 36));
}
/**
* 點擊登錄按鈕的事件處理
* @param e Action事件對象
*/
void btn_login_actionPerformed(ActionEvent e) {
//1:收集參數
String id = this.txt_userId.getText();
String pwd = new String(this.pwd_pwd.getPassword());
//1.1檢測數據
if (id == null || id.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "用戶編號不能為空");
return;
}
if (pwd == null || pwd.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "用戶口令不能為空");
return;
}
//2:
//3:調用邏輯層Api,并獲取返回值
boolean flag = UserFactory.getInstance().createUserEbi().login(id, pwd);
//4:根據返回值選擇新的Panel
if (flag) {
//使登錄界面不再出現
this.remove(this.txt_userId);
this.remove(this.pwd_pwd);
this.remove(this.btn_login);
this.remove(this.jLabel2);
this.remove(this.jLabel3);
this.updateUI();
//針對菜單進行簡單的權限控制
UserModel um = UserFactory.getInstance().createUserEbi().getUserModelById(
id);
this.mf.jMenuItem1.setEnabled(false);
this.mf.jMenuItem17.setEnabled(true);
if (um.getType() == um.TYPE_INT_1) {
this.mf.jMenu1.setEnabled(true);
this.mf.jMenu2.setEnabled(true);
this.mf.jMenu3.setEnabled(true);
this.mf.jMenu4.setEnabled(true);
this.mf.jMenu5.setEnabled(true);
}
else if (um.getType() == um.TYPE_INT_2) {
this.mf.jMenu3.setEnabled(true);
}
else if (um.getType() == um.TYPE_INT_3) {
this.mf.jMenu2.setEnabled(true);
}
else if (um.getType() == um.TYPE_INT_4) {
this.mf.jMenu1.setEnabled(true);
}
else if (um.getType() == um.TYPE_INT_5) {
this.mf.jMenu4.setEnabled(true);
}
else if (um.getType() == um.TYPE_INT_6) {
this.mf.jMenu5.setEnabled(true);
}
}else{
JOptionPane.showMessageDialog(null, "用戶編號或口令不正確");
}
}
}
//以下為事件處理中的Adaper類
class LoginPanel_btn_login_actionAdapter implements java.awt.event.ActionListener {
LoginPanel adaptee;
LoginPanel_btn_login_actionAdapter(LoginPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btn_login_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -