1

にゲームを実装しようとしていJavaFXます。FXMLまた、ファイルを扱っているので、mainクラスとcontrollerクラスがあります。main私の質問は、クラスからクラスのオブジェクトにどのように到達できるかcontrollerです。より明確にするために、簡単なコードを共有します。

これはメインクラスです:

public class JavaFXApplication1 extends Application {

    @Override
    public void start(Stage primaryStage) throws IOException {

        Parent root = FXMLLoader.load(getClass().getResource("Risk3.fxml"));

        // Main Pane
        BorderPane borderPane = new BorderPane();
        borderPane.setCenter(root);

        // Main scene
        Scene scene = new Scene(borderPane);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

たとえば、次のクラスに到達rootまたはクラスborderPaneから取得したいcontroller

public class SampleController implements Initializable {

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

rootグローバルと静的にするborderPane必要がありますか、またはそれらに到達する別の方法はありますか?

4

1 に答える 1