javafx fxml 最简示例

@Override
    public void start(Stage primaryStage) {
        try {
            //1,创建FXMLLoader
            //2,加载fxml文件,
            //3,取得pane
            //4,创建scene
            //5,设置stage
            //6,调用show方法
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Main.class.getResource("login.fxml"));
            AnchorPane pane = (AnchorPane) loader.load();
            Scene scene = new Scene(pane);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

你可能感兴趣的:(javafx)