简体   繁体   English

我似乎无法让RadioButton在JavaFX中工作

[英]I can't seem to get RadioButtons to work within JavaFX

I can't seem to get this block of code to work for RadioButtons. 我似乎无法让此代码块为RadioButtons工作。 It keeps on giving me an error for the new ChangeListener, the error being "The type ChangeListener is not generic; it cannot be parameterized with arguments ". 它不断给我新的ChangeListener一个错误,错误是“类型ChangeListener不是通用的;不能使用参数对其进行参数设置”。 However I can't find any examples which isn't like mine below. 但是我找不到下面不像我的例子。

group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
    public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
        if (patrolBut.isSelected()) {
            placeShipVert(patrolBoat, r, playerBoard, shapes);
        } else if (destroyerBut.isSelected()) {
            placeShipVert(destroyer, r, playerBoard, shapes);
        }
    }
});

Thanks for any help. 谢谢你的帮助。

Like in the comment above, have you imported the correct ChangeListener ? 就像上面的评论一样,您是否导入了正确的ChangeListener Depending on your IDE (eg Eclipse) you can set your errors and warnings on having to add a @Override annotation to your methods if they override a method. 根据您的IDE(例如Eclipse),您可以设置有关错误和警告的信息,如果它们重写方法,则必须在方法中添加@Override注释。 As you think you will have overriden a method (and thus added a @Override) the IDE would have warned you that in fact you didn't. 正如您认为的那样,您将重写方法(并因此添加了@Override),IDE会警告您实际上并没有。

If you use Java 8, I personally use change listeners as a Lambda: foo.addListener( (v, o, n) -> handleNewValue(n)); 如果您使用Java 8,则我个人将更改侦听器用作Lambda: foo.addListener( (v, o, n) -> handleNewValue(n));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM