Stage、Scene、Pane、Node的层次关系
Stage、Scene、Pane、Node代码(此例没有Pane)
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class App1 extends Application{
@Override
public void start(Stage primaryStage) {
Button bt = new Button("我是按钮");
Scene scene = new Scene(bt,210,80);
//↑宽210像素,高80像素 的窗口,放入bt这个控件↑
primaryStage.setTitle("我是JavaFX窗口");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
对上述代码块的解释
1、必须要有Stage(舞台)Stage可以理解为就是我们想要的窗口
2、必须在Stage上面放入一个Scene(场景)
3、Pane的作用是方便窗口的排版(即将控件整齐摆放)(可以将Node放在Pane上,也可以将Pane放在Pane上)
4、必须有Node(就是控件,如Button)
Application.launch启动的的时候调用的是start函数
主类必须要继承Application