编辑:我相信我终于找到了问题的正确答案。
原帖:
我目前正在尝试使用 JavaFX 和 EventBus 系统创建一个应用程序。为此,我必须在实例化其他类时将 EventBus 作为构造函数参数传递给它们。但是我不知道如何在使用 FXMLLoader 加载我的 .fxml 文件的同时执行此操作。
我的代码目前看起来像这样:
主班
public class MyApplication extends Application {
public void start(Stage stage) throws Exception {
EventBus eventBus = new EventBus();
>>> Here would be code that creates an Object of MainView, passing eventBus as constructor argument. <<<
Scene scene = new Scene(mainView);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
这个类继承自 BorderPane,我想使用 fxmlLoader 创建它的对象(我想。我不确定它是否像那样工作)
puplic class MainView extends BorderPane {
private EventBus …
Run Code Online (Sandbox Code Playgroud)