EventHandler不使用参数-Javafx



我已经为我的" mainwindow.fxml"文件构建了一个相当简单的控制器来处理按钮。我遵循本教程。我已经正确设置了FXML文档中的FX:ID。但是,在编译时,我会收到以下错误警告

java:type java.beans.eventhandler不使用参数

for Line

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?");
            }
        });
    }
}

任何帮助,请提前感谢。

您的导入不正确:

import java.awt.event.ActionEvent;
import java.beans.EventHandler;

应该是

import javafx.event.ActionEvent;
import javafx.event.EventHandler;

相关内容

  • 没有找到相关文章

最新更新