import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class MultipleStageDemo extends Application { @Override // Override the start method in the Application class public voidstart(Stage primaryStage) { // Create a scene and place a button in the scene Scene scene = new Scene(new Button("OK"),200,250); primaryStage.setTitle("MyJavaFX");// Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show();// Display the stage Stage stage = new Stage();// Create a new stage stage.setTitle("Second Stage");// Set the stage title // Set a scene with a button in the stage stage.setScene(new Scene(new Button("New Stage"),100,100)); stage.show();// Display the stage } }
说明:
1、本实例演示同时创建两个窗口,运行结果如下:
2、在默认的情况下,用户可自用更改窗口大小,如果想固定窗口大小,可以使用stage.setResizable(false)方法
3、本实例省略了main方法public static void main(String[] args) { Application.launch(args); }
用命令行的执行上述代码可以不需要main方法。
转载于:https://blog.51cto.com/fengbin8606/1418409