父节点、节点和场景之间的关系是什么?

What is the relationships between Parents, Nodes and Scenes?

我问的是节点、场景和父级之间的关系。我实际上正在研究 JavaFX 并且很难在同一帧中更改场景。我找到了一种方法来做到这一点,但实际上我不知道它是如何工作的。你能帮我弄清楚吗?

我尝试在 Java 参考资料、youtube 上寻找,也在 google 上写下关键字 "Scenes Parent",但我没有找到任何对我有帮助的东西。

public class SceneCreator {

  // launching the new scene based on the .fxml file name passed in the argument as a String variable
  // building the scene and setting the value for the instance variable loader
  public static void launchScene (String sceneName) throws IOException {

    // Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    FXMLLoader loader = new FXMLLoader(Main.class.getResource(sceneName));
    Main.setRoot(loader.load());
    Scene scene = new Scene(Main.getRoot());
    Main.getStage().setScene(scene);
    Main.getStage().show();



@FXML
  private void sphereClick() throws IOException{
    System.out.println("Sphere button clicked");
    SceneCreator.launchScene("sphere.fxml");
  }

欢迎来到 Whosebug,请在提问前仔细搜索,但要在此处找到答案:

JavaFX scene 图是顶层的一部分,是起始层 构建 JavaFX 应用程序的要点。

它是一个层次结构的节点树,代表应用程序用户界面的所有视觉元素。可以处理输入,可以渲染,参考图片

场景图中的单个元素称为 node。每个 node 都有一个 IDstyle classbounding volume

场景图中的每个节点都有一个single parentzero or more children

请看下面这本书,70页左右,很有帮助,既然在学,就没有时间浪费 https://docs.oracle.com/javase/8/javafx/JFXST.pdf

参考 Whosebug 问题,它们真的很有帮助,而且它们针对您的问题,例如这个问题:

How to swap screens in a javafx-application in the controller-class?

或者这个