📄 landframe.java
字号:
/**
* 源文件:LandFrame.java
* 作用:用户登陆进入系统
*/
package mypro;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LandFrame extends JDialog implements ActionListener
{
static String strCode;
private JLabel labCode,labPwd,labTitle,labClue;
private JTextField txtCode;
private JPasswordField pwd;
private JButton btnLand,btnExit;
static
{
//设置窗体为豪华框架
JDialog.setDefaultLookAndFeelDecorated(true);
}
public LandFrame()
{
labTitle =new JLabel("员工登陆");
labCode=new JLabel("员工工号");
labPwd=new JLabel("密码");
labClue=new JLabel("请输入工号和密码登陆");
txtCode=new JTextField();
pwd=new JPasswordField();
btnLand=new JButton("登陆");
btnExit=new JButton("退出");
labTitle.setFont(new Font("华文新魏", Font.BOLD | Font.ITALIC, 25));
labTitle.setHorizontalAlignment(SwingConstants.CENTER);
labTitle.setBounds(new Rectangle(77, 17, 221, 35));
labCode.setBounds(new Rectangle(64, 82, 76, 25));
labPwd.setBounds(new Rectangle(64, 125, 76, 25));
txtCode.setBounds(new Rectangle(154, 81, 156, 25));
pwd.setBounds(new Rectangle(154, 123, 156, 25));
btnLand.setBounds(new Rectangle(64, 177, 91, 28));
btnLand.setActionCommand("Land");
btnLand.setToolTipText("登陆进入系统");
btnExit.setBounds(new Rectangle(219, 177, 91, 28));
btnExit.setActionCommand("Exit");
btnExit.setToolTipText("放弃登陆");
btnLand.addActionListener(this);
btnExit.addActionListener(this);
labClue.setHorizontalAlignment(SwingConstants.CENTER);
labClue.setBounds(new Rectangle(77, 208, 221, 35));
Container me=this.getContentPane();
me.setLayout(null);
me.add(labTitle);
me.add(labCode);
me.add(labPwd);
me.add(labClue);
me.add(txtCode);
me.add(pwd);
me.add(btnLand);
me.add(btnExit);
this.setTitle("员工登陆");
this.setSize(375, 288);
this.setResizable(false);
this.setLocationRelativeTo(this);
this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent lae)
{
String strbtn=lae.getActionCommand();
if(strbtn.equals("Land"))
{
strCode=txtCode.getText().trim();
String strPwd=pwd.getText();
Check check=new Check();
UsersData ud = new UsersData();
ud.setUserCode(strCode);
ud.setPwd(strPwd);
if(strCode.length()==0)
{
JOptionPane.showMessageDialog(null,"请输入工号","提示",JOptionPane.INFORMATION_MESSAGE);
txtCode.requestFocus();
}
else if(strPwd.length()!=6)
{
JOptionPane.showMessageDialog(null,"请输入六位数密码","提示",JOptionPane.INFORMATION_MESSAGE);
pwd.setText("");
pwd.requestFocus();
}
else if(check.checkCodeAndPwd(ud))
{
if(strCode.equals("A000"))
{
MainFrame main=new MainFrame();
main.menuUsers.setEnabled(true);
main.btnUsers.setEnabled(true);
this.dispose();
}
else
{
new MainFrame();
this.dispose();
}
}
else
{
JOptionPane.showMessageDialog(null, "工号或者密码不正确,", "登陆失败", JOptionPane.ERROR_MESSAGE);
txtCode.setText("");
pwd.setText("");
txtCode.requestFocus();
}
}
else if (strbtn.equals("Exit"))
{
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -