0
나는 선택된 파이 차트 슬라이스의 비율을 보여 주려고했습니다. Google에서 검색했으며 모든 사용자가 마우스 이벤트와 함께 새 이벤트 핸들러를 추가하고 있습니다. 코드를 구현하려고 할 때마다 다음 오류가 발생합니다.javafx piechart가 이벤트 핸들러를 추가 할 수 없습니다.
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>)
내가 뭘 잘못하고 있니? 나는 오류와 함께 구글 검색 시도했지만 아무것도 그것의 왔어. 문제
컨트롤러 :
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;
}
}
감사
편집 : 추가 된 전체 컨트롤러
전체 파일을 포함하십시오. 가장 가능성있는 설명은 JavaFX 대신 AWT 또는 Swing 버전의 'MouseEvent'를 가져 왔습니다. – Itai
@sillyfly 게시물을 편집했습니다 – Bas
@sillyfly javafx 변형을 가져 오기로 바꿨습니다. 작동합니다. 도와 주셔서 감사합니다. 답변으로 게시하여 받아 들일 수 있습니까? – Bas