java登录判断密码是否正确怎么写代码_java 判断两次输入密码是否一致

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

jslwz007

推荐于 2018.03.09

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:46%    等级:12

已帮助:6219人

焦点事件必须是在4102confirm输入之后调用才能起作用

import java.awt.FlowLayout;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

public class PwdValidation {

public static void main(String[] args) {

1653JFrame f = new JFrame("Validation");

JLabel pwd = new JLabel("Input");

JLabel confirm = new JLabel("Confirm");

final JTextField password = new JTextField(15);

final JTextField cfmPwd = new JTextField(15);

f.add(pwd);

f.add(password);

f.add(confirm);

f.add(cfmPwd);

cfmPwd.addFocusListener(new FocusListener(){

public void focusGained(FocusEvent e) {}

public void focusLost(FocusEvent e) {

if(!password.getText().equals(cfmPwd.getTreeLock())){

JOptionPane.showMessageDialog(null, "Passowrd not same, please input again!","Warning",JOptionPane.WARNING_MESSAGE);

password.setText("");

cfmPwd.setText("");

}

}

});

f.setLayout(new FlowLayout());

f.pack();

f.setVisible(true);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

01分享举报

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值