【发布时间】:2017-06-09 18:17:17
【问题描述】:
我写了这个方法,因为我想在按下按钮时检查所有地方,如果文本字段、日期选择器和单选按钮为空,但它不起作用。
我应该在这段代码中更正什么,或者我应该以不同的方式做一个方法?
public void btn1(ActionEvent event) throws Exception {
if(name.getText().trim().isEmpty() && surname.getText().trim().isEmpty() && pesel.getText().trim().isEmpty() && adres.getText().trim().isEmpty() && email.getText().trim().isEmpty() )
if(dateOfBirth.getValue() == null)
if(sexM.isSelected() || sexF.isSelected() || sexG.isSelected()){
lbl.setText("All of places have to be filled");
} else {
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("\\Step2.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
}
}
}
【问题讨论】:
-
你只想要所有个都是空的错误信息吗?
-
此外,通过使用 3 个 if 而不是一个,在某些情况下既没有设置标签的文本,也没有显示新阶段。 (如果其中一个文本字段不为空或日期选择器不为空。)这是期望的行为吗?
-
@XtrEmE 我的代码对你有用吗??
标签: javafx datepicker radio-button textfield fxml