简体   繁体   English

检查所有JtextFields和Password后,如何使actionListener使用if / else语句执行操作

[英]How do I make the actionListener use if/else statement to execute an operation after all the JtextFields and Password have been checked

    JButton btnSubmit = new JButton("Submit");
    btnSubmit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String  firstName = firstNameField.getText();\\gets user input
            String  surname =   surnameField.getText();\\gets user input
            String  username    =   usernameField.getText();\\gets user input
            char[] newPassword  =   password.getPassword();
            char[] confirmNew   =   confirmPassword.getPassword();

How do I make below conditional statement check if all fields are completed and displays the completion responses. 如何在下面的条件语句中进行检查所有字段是否都已填写并显示完成响应。

            if(firstName == null && surname ==null && username == null && newPassword == null && confirmNew ==  null){
                completionResponse.setText("All fields must be completed");
            }else
            completionResponse.setText("Congratulations! account have been successfully created");
        }

    });

Now you are checking if all fields == null, which is probably false (assuming at least something is filled in). 现在,您要检查是否所有字段== null,这可能是错误的(假设至少填写了一些内容)。

if(firstName == null || surname ==null || username == null || newPassword == null || confirmNew ==  null){
completionResponse.setText("All fields must be completed");
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果一个或多个变量小于0,如何使if语句不执行并转到else if语句? - How do I make an if statement not execute and go to the else if statement if one or more variables are less than 0? 在带有 ActionListener 和 if-else 语句的 JFrame 上使用 JTextFields、JButtons 和 JLabels Jbutton 不起作用 - Using JTextFields, JButtons and JLabels on JFrame with ActionListener and if-else Statement Jbutton Does Not Work Java-如何对多个JTextField使用单个FocusListener? - Java - How do I use a single FocusListener for multiple JTextFields? 如何在 ActionListener 中使用 JLabel? - How do I use JLabel in ActionListener? 如何在Java中使用ActionListener(this)命令 - How do I use the ActionListener (this) command in Java 初始化所有 servlet 后,如何在 Java Webapp 中执行一次操作? - How do I perform one time actions in a Java Webapp AFTER all servlets have been initialized? 如何在 Java 中的 if else 语句中检测所有特殊字符? - How do I detect all special characters in an if else statement in Java? 按下按钮后,如何使GUI驱动程序类中的变量转移到ActionListener类中? - How do I make the the variables in my GUI Driver class to be transferred to the ActionListener class after a button is pressed? 如何将 contains 方法与“if, else”语句一起使用? - How do I use the contains method with "if, else" statement? 如何在 java 中使用 ActionListener 执行多个操作? - How do I have multiple actions performed with an ActionListener in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM