What is the relationships between Parents, Nodes and Scenes?

问题: I'm asking regarding the relationships between Nodes, Scenes and Parents. I'm actually studying JavaFX and is difficult change scenes in the same frame. I founded a way for...

问题:

I'm asking regarding the relationships between Nodes, Scenes and Parents. I'm actually studying JavaFX and is difficult change scenes in the same frame. I founded a way for do that, but actually I don't know how it works. Can you help me figure it out ?

I tried looking for on the Java reference, on youtube and also writing on google the keyword "Scenes Parent" but I didn't found anything that helped me.

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:

Welcome to StackOverFlow, Please search very thouroghly before asking a question, but to target the answer here:

The JavaFX scene graph is part of the top layer and is the starting point for constructing a JavaFX application.

It is a hierarchical tree of nodes that represents all of the visual elements of the application’s user interface. It can handle input and can be rendered, refer to the pictureenter image description here

A single element in a scene graph is called a node. Each node has an ID, style class, and bounding volume.

each node in a scene graph has a single parent and zero or more children

please read the following book it is around 70 pages but its very helpful, and since you are studying it, there is not time wasted https://docs.oracle.com/javase/8/javafx/JFXST.pdf

Refer to stackoverflow questions, they can be really helpful and they target your very question, such as this one:

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

or this one

How to switch scenes in JavaFX

  • 发表于 2019-02-18 20:21
  • 阅读 ( 172 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除