JavaFx的Application、舞台Stage和場景Scene初探


import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class App14_1 extends Application {
    @Override
    public void start(Stage primaryStage) {

        // 創建一個按鈕
        Button button = new Button("我是按鈕");

        // 創建一個組
        Group group = new Group();
        group.getChildren().addAll(button);

        Scene scene = new Scene(group, 210, 80);

        // 將場景至於窗口中
        primaryStage.setScene(scene);
        // 設置窗口是否在頂層
        primaryStage.setAlwaysOnTop(true);
        // 設置是否可以改變窗口的大小
        primaryStage.setResizable(false);
        // 設置窗口是否可以最大化
        primaryStage.setMaximized(false);
        // 設置窗口的寬度
        primaryStage.setWidth(800);
        // 設置窗口的高度
        primaryStage.setHeight(600);
        // 設置窗口的標題
        primaryStage.setTitle("我的JavaFx窗口");
        // 設置該窗口的x和y屬性,使其位於當前屏幕的中心
        primaryStage.centerOnScreen();
        // 顯示窗口
        primaryStage.show();

    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
import javafx.application.Application;

import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class App14_2 extends Application {
    @Override
    public void start(Stage primaryStage) {

        Button button = new Button("我是按鈕");
        Scene scene1 = new Scene(button, 210, 80);
        primaryStage.setTitle("我是主舞台");
        primaryStage.setScene(scene1);
        primaryStage.show();


        Stage stage = new Stage();
        stage.setAlwaysOnTop(true);
        stage.setTitle("第二個舞台");
        Button button1 = new Button("我也是一個按鈕");
        stage.setScene(new Scene(button1, 180, 100));
        stage.show();

    }

    public static void main(String[] args) {
        Application.launch(args);
    }

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM