如何制作 if 语句来检查所有或只有一个文本字段是否为空

How to make if statement that checks if all or just one text field is empty

如何创建一个 if 语句来检查是所有文本字段还是只有一个文本字段为空

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
    if(jTextField1.getText().equals("") && jTextField2.getText().equals("") && jTextField3.getText().equals("")){
            JOptionPane.showMessageDialog(null, " please fill empty fields", "Input Error",JOptionPane.ERROR_MESSAGE);
    }else{
    }
}

您可以使用整型变量作为计数器,如果 jTextfield 为空,您可以增加计数器。

我所做的是用 "or" 语句列出所有小部件:

 if ((attribut1.isEmpty() || attribut2.isEmpty() || attribut3.isEmpty() || attribut4.isEmpty()||attribut5.isEmpty()||attribut6.isEmpty()||attribut7.isEmpty()||attribut8.isEmpty()||attribut9.isEmpty()||attribut10.isEmpty())) {
        Toast.makeText(this, "fill in all details"

绝对不是最好的解决方案,但它确实有效。