【发布时间】:2018-11-13 05:17:58
【问题描述】:
我希望我的代码检查表单中的文本字段是否为空,然后显示弹出警报消息。我的问题是,即使文本字段已填写,只要我点击“ENTER”就会弹出此警报消息。任何帮助表示赞赏!
BtnEnter.setOnAction((ActionEvent e) -> {
if (txtfName.getText().isEmpty() | txtlName.getText().isEmpty() |
txtMI.getText().isEmpty() | txtStreeAdd.getText().isEmpty()
| txtCity.getText().isEmpty() | txtZip.getText().isEmpty()
| txtPhone.getText().isEmpty() | txtEmail.getText().isEmpty()
| txtSecEmail.getText().isEmpty()) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Warning");
alert.setHeaderText("Required Fields Empty");
alert.setContentText("The fields highlighted in red must be filled "
+ "out.\nPlease try again.");
alert.showAndWait();
【问题讨论】:
-
|怎么了?也许||? -
我不知道,但
|似乎是bitwise or。 -
您也可以采取this 的方法或从中获取想法。
-
我个人认为
|和||不会影响整体结果。|和||的区别在于||是一个短路运算符 - 即使您链接其中的 1000 个,整个表达式将返回true,只要它找到第一个计算的子表达式到true。|将简单地评估所有。
标签: javafx