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

问题描述 投票:1回答:1

我问的是节点,场景和父母之间的关系。我实际上正在研究JavaFX并且难以在同一帧中更改场景。我找到了这样做的方法,但实际上我不知道它是如何工作的。你能帮我解决一下吗?

我尝试在youtube上查找Java参考,并在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");
  }
java javafx nodes parent
1个回答
1
投票

欢迎来到StackOverFlow,请在提问前先搜索,但要在这里找到答案:

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

它是一个分层的节点树,代表应用程序用户界面的所有可视元素。它可以处理输入并可以渲染,请参考pictureenter image description here

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

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

请阅读以下书籍,大约70页,但它非常有帮助,因为你正在研究它,没有时间浪费https://docs.oracle.com/javase/8/javafx/JFXST.pdf

请参阅stackoverflow问题,它们可能非常有用,它们针对您的问题,例如:

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

或者这个

How to switch scenes in JavaFX

© www.soinside.com 2019 - 2024. All rights reserved.