首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查JPasswordField是否为空?

如何检查JPasswordField是否为空?
EN

Stack Overflow用户
提问于 2021-05-26 15:50:47
回答 1查看 62关注 0票数 0

这段代码的对立面是什么--> password.getPassword().length == 0

例如,不是空的,而是检查它是否已填满。

代码语言:javascript
复制
JButton confirm = new JButton("Sign Up");
confirm.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    UserInfo a = new UserInfo();

    /*here is my problem I want it to Check if someone inputted a password so I can 
                proceed to open the second frame */


    if(!firstname.getText().trim().isEmpty() && !lastname.getText().trim().isEmpty() &&  password.getPassword().length == 0 && pass2.getPassword().length == 0
        && !address.getText().trim().isEmpty() )
    
    a.frame2.setVisible(true);
    frame.dispose(); 
      
    
    if(firstname.getText().trim().isEmpty()) {
      missingfirst.setText("Please Add Your First Name.");
  
    }
    if(lastname.getText().trim().isEmpty()) {
      missinglast.setText("Please Add Your Last Name.");
    }
    if(password.getPassword().length == 0) {
      missingpass.setText("Please Add A Password.");
    }
    if(pass2.getPassword().length == 0) {
      missingrepass.setText("Please Re-Type Your Password.");
    }
    if(address.getText().trim().isEmpty()) {
      missingadd.setText("Please Enter An Address.");
    }
    
    else if (!(password.getPassword().equals(pass2.getPassword()))) {
      missingrepass.setText("Password Doesn't Match.");
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-05-26 16:16:48

使用password.getPassword().length > 0!password.getPassword().isEmpty()进行检查。

我认为在这里你应该验证输入的密码格式是否正确,而不是检查它是否填写。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67700691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档