首页>代码>Java swing简单个人信息管理器>/People/src/com/text1/LoginFrame.java
package com.text1;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JTextField;

public class LoginFrame extends JFrame implements ActionListener {
    /****************************定义各控件**************************/
    private Icon welcomeIcon=new ImageIcon("welcome.png");
    private JLabel lbWelcome=new JLabel(welcomeIcon);
    private JLabel lbAccount=new JLabel("请您输入账号");
    private JTextField tfAccount=new JTextField(10);
    private JLabel lbPassword=new JLabel("请您输入密码");
    private JPasswordField pfPassword=new JPasswordField(10);
    private JButton btLogin=new JButton("登录");
    private JButton btRegister=new JButton("注册");
    private JButton btExit=new JButton("退出");
    public LoginFrame() {
        /**********************界面初始化*****************************/
        super("登录");
        this.setLayout(new FlowLayout());
        this.add(lbWelcome);
        this.add(lbAccount);
        this.add(tfAccount);
        this.add(lbPassword);
        this.add(pfPassword);
        this.add(btLogin);
        this.add(btRegister);
        this.add(btExit);
        this.setSize(240,180);
        GUIUtil.toCenter(this);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.setVisible(true);
        /*****************************增加监听************************/
        btLogin.addActionListener(this);
        btRegister.addActionListener(this);
        btExit.addActionListener(this);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==btLogin) {
            String account=tfAccount.getText();
            String password=new String(pfPassword.getPassword());
            FileOpe.getInfoByAccount(account);
            if(Conf.account==null||!Conf.password.equals(password)) {
                JOptionPane.showMessageDialog(this,"登录失败");
                return;
            }
            JOptionPane.showMessageDialog(this,"登录成功");
            this.dispose();
            new OperationFrame();
        }
        else if(e.getSource()==btRegister) {
            this.dispose();
            new RegisterFrame();
        }
        else {
            JOptionPane.showMessageDialog(this,"谢谢光临");
            System.exit(0);
        }
    }
}
最近下载更多
YZN111  LV3 2023年12月12日
1219610676  LV4 2023年12月7日
yangxb2  LV10 2023年10月20日
linmou  LV8 2023年3月13日
朱俪的邮件及存储  LV8 2023年2月27日
Willson88888  LV3 2022年12月7日
奶油味儿的小透明  LV1 2022年12月5日
VIOLENTIO  LV1 2022年11月8日
闫小玥  LV8 2021年12月22日
Undead  LV2 2021年12月14日
最近浏览更多
uid0901  LV2 3月14日
lshlsh 2023年12月25日
暂无贡献等级
shiaomon 2023年12月14日
暂无贡献等级
YZN111  LV3 2023年12月12日
1219610676  LV4 2023年12月7日
李朝磊  LV18 2023年11月18日
121231 2023年11月9日
暂无贡献等级
yangxb2  LV10 2023年10月20日
卢本伟不开挂  LV4 2023年9月14日
榆安安 2023年6月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友