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分享举报


版权声明:本文为weixin_31499919原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。