javafx piechart可以';不添加事件处理程序

javafx piechart可以';不添加事件处理程序,javafx,pie-chart,Javafx,Pie Chart,我一直在尝试显示所选piechart切片的百分比。我在Google上搜索过,每个人都在添加一个带有鼠标事件的新eventhandler。每当我尝试实现代码时,都会出现以下错误: method addEventHandler in class Node cannot be applied to given types; required: EventType<T>,EventHandler<? super T> found: int,<anonymous Ev

我一直在尝试显示所选piechart切片的百分比。我在Google上搜索过,每个人都在添加一个带有鼠标事件的新eventhandler。每当我尝试实现代码时,都会出现以下错误:

method addEventHandler in class Node cannot be applied to given types;
  required: EventType<T>,EventHandler<? super T>
  found: int,<anonymous EventHandler<MouseEvent>>
  reason: cannot infer type-variable(s) T
    (argument mismatch; int cannot be converted to EventType<T>)
  where T is a type-variable:
    T extends Event declared in method <T>addEventHandler(EventType<T>,EventHandler<? super T>)
类节点中的方法addEventHandler不能应用于给定类型;
必需:EventType,EventHandler该错误是由于错误地导入了
java.awt.event.MouseEvent
而不是
javafx.scene.input.MouseEvent
。最大的提示是,实际类型是
int
,而不是
EventType
,这意味着导入不匹配-较旧的API倾向于使用静态整数常量,而较新的API更喜欢枚举

请包含完整的文件-最可能的解释是您导入了AWT或Swing版本的
MouseEvent
,而不是JavaFX。@sillyfly我编辑了post@sillyfly我已经用javafx变体替换了导入,它可以正常工作。谢谢你的帮助。你能把这个作为答案贴出来让我接受吗?
package com.hva.fastenyourseatbelt;

import java.awt.event.MouseEvent;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.chart.PieChart;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import utilities.DatabaseUtils;
import static utilities.StatisticsUtils.giveAirports;

/**
 * FXML Controller class
 *
 * @author Mourad A
 */
public class FXMLStatistiekenController implements Initializable {

    /**
     * Initializes the controller class.
     */
    @FXML
    private ComboBox<String> CBStatisticsCountry;

    @FXML
    private ComboBox<String> CBStatisticsAirport;

    @FXML
    private ComboBox<String> CBStatistiekenYear;

    @FXML
    private ComboBox<String> CBStatistiekenMonth;

    @FXML
    private PieChart pieChart;

    @Override
    public void initialize(URL url, ResourceBundle rb) {

        ObservableList list = DatabaseUtils.getType();

        pieChart.setData(list);
        pieChart.setTitle("Type bagage");

        final Label caption = new Label("");
        caption.setTextFill(Color.DARKORANGE);
        caption.setStyle("-fx-font: 24 arial;");

        for (final PieChart.Data data : pieChart.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()) + "%");
                }
            });
        }
    }

    @FXML
    private String receiveCountries(ActionEvent event) {
        String country = CBStatisticsCountry.getValue();
        return country;
    }


}