【发布时间】:2018-04-14 12:22:36
【问题描述】:
我有一个程序,用户必须在其中注册并在注册场景中使用 RadioButton 选择性别: Screenshot of the program running
我有一个变量“gender”,它是一个字符;我希望程序将此字符更改为“m”或“f”,具体取决于 RadioButton 用户按下的内容(“m”代表男性,“f”代表女性)。 这是我现在拥有的,但它不起作用:
@FXML
private RadioButton male;
@FXML
private RadioButton female;
private char gender;
male.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
gender = 'm';
}
});
female.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
gender = 'f';
}
});
感谢您的时间和精力!
【问题讨论】:
-
什么不起作用?它在哪里不起作用?有错误吗?
-
@Steven 性别返回为 null,无论是否按下 RadioButton。
标签: java javafx radio-button