?? loginframe.java~73~
字號:
package loginInterface;
import java.awt.*;
import javax.swing.*;
import data.*;
import java.awt.event.*;
import java.awt.Rectangle;
public class LoginFrame extends JFrame implements ActionListener {
//初始化部件
JPanel pnlMain;
JLabel lblLogin, lblUserName, lblPwd;
JTextField txtUserName;
JPasswordField pwdPassword;
JButton btnLogin, btnCancel;
//構造函數
public LoginFrame() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void jbInit() throws Exception {
//取得窗口面板
pnlMain = (JPanel)this.getContentPane();
pnlMain.setLayout(null);
//定義窗口的大小和標題
this.setSize(new Dimension(350, 300));
this.setTitle("登錄模塊");
//定義標簽的標題
lblLogin = new JLabel("人事管理系統");
lblLogin.setFont(new Font("黑體", Font.BOLD, 24));
lblUserName = new JLabel("用戶名:");
txtUserName = new JTextField("");
lblPwd = new JLabel("密 碼:");
pwdPassword = new JPasswordField("");
btnLogin = new JButton("登錄");
btnCancel = new JButton("取消");
Font font = new Font("宋體", Font.PLAIN, 14);
lblUserName.setFont(font);
lblUserName.setForeground(Color.blue);
lblPwd.setFont(font);
lblPwd.setForeground(Color.blue);
btnLogin.setFont(font);
btnLogin.setForeground(Color.blue);
btnCancel.setFont(font);
btnCancel.setForeground(Color.blue);
lblLogin.setForeground(Color.green);
//設置組件位置
lblLogin.setBounds(new Rectangle(118, 25, 150, 40));
lblUserName.setBounds(new Rectangle(83, 95, 81, 16));
txtUserName.setCaretColor(Color.green);
txtUserName.setBounds(new Rectangle(153, 94, 132, 22));
lblPwd.setBounds(new Rectangle(84, 151, 79, 16));
pwdPassword.setCaretColor(Color.green);
pwdPassword.setBounds(new Rectangle(154, 148, 132, 22));
btnLogin.setBackground(Color.cyan);
btnLogin.setBounds(new Rectangle(34, 206, 109, 25));
btnCancel.setBackground(Color.cyan);
btnCancel.setBounds(new Rectangle(206, 207, 109, 25));
pnlMain.add(lblLogin);
pnlMain.add(btnLogin);
pnlMain.add(btnCancel);
pnlMain.add(txtUserName);
pnlMain.add(lblUserName);
pnlMain.add(pwdPassword);
pnlMain.add(lblPwd);
btnLogin.addActionListener(this);
btnCancel.addActionListener(this);
}
//按鈕執行事件
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == btnLogin) {
String name = txtUserName.getText().trim();
String pwd = new String(pwdPassword.getPassword());
LoginData login = new LoginData();
boolean check = login.checkUser(name, pwd);
//顯示提示信息
if (check) {
JOptionPane.showMessageDialog(null, "登錄成功");
} else {
JOptionPane.showMessageDialog(null, "用戶名或密碼錯誤!");
}
}
if (ae.getSource().equals(btnCancel)) {
//清空內存
System.exit(0);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -