首页>代码>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);
        }
    }
}
最近下载更多
120_wu  LV4 2024年12月3日
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日
最近浏览更多
11999333  LV3 6月12日
pxqtsht  LV16 2月21日
DoustrongWU  LV5 2月16日
120_wu  LV4 2024年12月3日
233002037  LV3 2024年10月20日
uid0901  LV3 2024年3月14日
lshlsh 2023年12月25日
暂无贡献等级
shiaomon 2023年12月14日
暂无贡献等级
YZN111  LV3 2023年12月12日
1219610676  LV4 2023年12月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友