JavaFX - Stage 参数的意义何在?
JavaFX - What is the point of the Stage argument?
我正在学习本教程:https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm
上面写着:
"A JavaFX application defines the user interface container by means of a stage and a scene. The JavaFX Stage class is the top-level JavaFX container. The JavaFX Scene class is the container for all content..."
"In JavaFX, the content of the scene is represented as a hierarchical scene graph of nodes. In this example, the root node is a StackPane object..."
我不明白 Stage 对象的意义是什么。如果 StackPane 是根节点(我理解整个树结构的东西),如果 Scene 是所有内容的容器,那么 Stage 在做什么?为什么不能由 Scene 完成?
代码如下:
public class HelloWorld extends Application {
@Override
public void start(Stage primaryStage) {
// TODO Auto-generated method stub
Button btn = new Button("Say 'Hello World'");
btn.setOnAction((ActionEvent event) -> System.out.println("Hello World!"));
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这基本上是一个关注点的分离。
Stage
是一个 object 用于修改外观、标题、位置等。 window
中的 Scene
用于布局和处理事件等..
单独实现功能 类 是一项设计决策,很可能还受到以下事实的影响:window 由 OS 提供,如果场景完全呈现,由window里面的工具包提供。
但是 Scene
也可用于将 JavaFX 嵌入其他 GUI 库的容器中(FXCanvas
、JFXPanel
)。
我正在学习本教程:https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm
上面写着:
"A JavaFX application defines the user interface container by means of a stage and a scene. The JavaFX Stage class is the top-level JavaFX container. The JavaFX Scene class is the container for all content..."
"In JavaFX, the content of the scene is represented as a hierarchical scene graph of nodes. In this example, the root node is a StackPane object..."
我不明白 Stage 对象的意义是什么。如果 StackPane 是根节点(我理解整个树结构的东西),如果 Scene 是所有内容的容器,那么 Stage 在做什么?为什么不能由 Scene 完成?
代码如下:
public class HelloWorld extends Application {
@Override
public void start(Stage primaryStage) {
// TODO Auto-generated method stub
Button btn = new Button("Say 'Hello World'");
btn.setOnAction((ActionEvent event) -> System.out.println("Hello World!"));
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这基本上是一个关注点的分离。
Stage
是一个 object 用于修改外观、标题、位置等。 window
中的 Scene
用于布局和处理事件等..
单独实现功能 类 是一项设计决策,很可能还受到以下事实的影响:window 由 OS 提供,如果场景完全呈现,由window里面的工具包提供。
但是 Scene
也可用于将 JavaFX 嵌入其他 GUI 库的容器中(FXCanvas
、JFXPanel
)。