[英]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.