📜  如何将侦听器添加到切换组单选按钮 javafx - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:34.511000             🧑  作者: Mango

代码示例1
ToggleGroup genderGroup = new ToggleGroup();
male.setToggleGroup(genderGroup);
female.setToggleGroup(genderGroup);
genderGroup.selectedToggleProperty().addListener(
   (observable, oldToggle, newToggle) -> {
       if (newToggle == male) {
           gender = 'm';
       } else if (newToggle == female) {
           gender = 'f';
       } else {
           gender = '?';
       }
    }
);