提问者:小点点

父母、节点和场景之间有什么关系?


我问的是节点、场景和父母之间的关系。我实际上正在学习JavaFX,很难在同一个画面中改变场景。我找到了做那件事的方法,但实际上我不知道它是如何工作的。你能帮我弄清楚吗?

我试着在Java参考资料、youtube上寻找,也在谷歌上写下关键词“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");
  }

共1个答案

匿名用户

欢迎来到StackOverFlow,请在提问前仔细搜索,并在此寻找答案:

JavaFX 场景图是顶层的一部分,是构造 JavaFX 应用程序的起点。

场景图中的单个元素称为节点。每个节点都有一个ID样式类边界卷

场景图中的每个节点都有一个< code >单个父节点和< code >零个或多个子节点

请阅读下面这本书,大约70页,但它很有帮助,既然你正在学习,就不会浪费时间https://docs.oracle.com/javase/8/javafx/JFXST.pdf

请参阅stackoverflow问题,它们非常有帮助,并且它们针对您的问题,例如:

如何在控制器类的javafx应用程序中交换屏幕?

或者这个

如何在 JavaFX 中切换场景