?? loginframe.java~77~
字號(hào):
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;
//構(gòu)造函數(shù)
public LoginFrame() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void jbInit() throws Exception {
//取得窗口面板
pnlMain = (JPanel)this.getContentPane();
pnlMain.setLayout(null);
//定義窗口的大小和標(biāo)題
this.setSize(new Dimension(350, 300));
this.setTitle("登錄模塊");
//定義標(biāo)簽的標(biāo)題
lblLogin = new JLabel("人事管理系統(tǒng)");
lblLogin.setFont(new Font("黑體", Font.BOLD, 24));
lblUserName = new JLabel("用戶(hù)名:");
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);
//設(shè)置組件位置
lblLogin.setBounds(new Rectangle(92, 30, 150, 40));
lblUserName.setBounds(new Rectangle(67, 103, 81, 16));
txtUserName.setCaretColor(Color.green);
txtUserName.setBounds(new Rectangle(137, 102, 132, 22));
lblPwd.setBounds(new Rectangle(68, 159, 79, 16));
pwdPassword.setCaretColor(Color.green);
pwdPassword.setBounds(new Rectangle(138, 156, 132, 22));
btnLogin.setBackground(Color.cyan);
btnLogin.setBounds(new Rectangle(29, 213, 109, 25));
btnCancel.setBackground(Color.cyan);
btnCancel.setBounds(new Rectangle(201, 214, 109, 25));
pnlMain.add(lblLogin);
pnlMain.add(btnCancel);
pnlMain.add(btnLogin);
pnlMain.add(txtUserName);
pnlMain.add(lblUserName);
pnlMain.add(pwdPassword);
pnlMain.add(lblPwd);
btnLogin.addActionListener(this);
btnCancel.addActionListener(this);
}
//按鈕執(zhí)行事件
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, "用戶(hù)名或密碼錯(cuò)誤!");
}
}
if (ae.getSource().equals(btnCancel)) {
//清空內(nèi)存
System.exit(0);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -