我创建了一个 javafx 饼图,并希望在用户单击饼图的一部分时做一些事情。我正在关注本教程:
for (final PieChart.Data data : chart.getData()) {
data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED,
new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent e) {
caption.setTranslateX(e.getSceneX());
caption.setTranslateY(e.getSceneY());
caption.setText(String.valueOf(data.getPieValue()) + "%");
}
});
我在编译之前收到这些错误警告:在“.addEventHandler”上
Bound mismatch: The generic method addEventHandler(EventType<T>, EventHandler<?
superT>) of type Node is not applicable for the arguments (Integer, new
EventHandler<MouseEvent> (){}). The inferred type MouseEvent&Event is not a valid
substitute for the bounded parameter <T extends Event>
在“事件处理程序”上
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter
<T extends Event> of the type EventHandler<T>
有人对我为什么会收到这些错误有任何见解吗?