我为我的" MainWindow.fxml"构建了一个相当简单的控制器。文件来处理按钮。我按照this教程。我已经在fxml doc中正确设置了fx:id。但是在编译时我收到以下错误警告
java:type java.beans.EventHandler不接受参数
为行
createVizButton.setOnAction(new EventHandler<ActionEvent>(){
我的完整控制器类看起来如下......
package sample;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import java.awt.event.ActionEvent;
import java.beans.EventHandler;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.scene.control.Button;
public class MainController implements Initializable{
@FXML
private Button createVizButton;
@Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
assert createVizButton != null : "fx:id=\"createButton\" was not injected: check your FXML file 'MainWindow.fxml'.";
// initialize your logic here: all @FXML variables will have been injected
createVizButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
System.out.println("That was easy, wasn't it?");
}
});
}
}
任何帮助表示感谢,提前谢谢。
答案 0 :(得分:2)
您的导入不正确:
import java.awt.event.ActionEvent;
import java.beans.EventHandler;
应该是
import javafx.event.ActionEvent;
import javafx.event.EventHandler;