只需要集成Application 就可以了
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class test extends Application {
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
// 设置舞台标题
primaryStage.setTitle("Hello World App");
// 创建按钮
Button button = new Button("Click Me");
// 设置按钮点击事件处理逻辑
button.setOnAction(event -> {
// 创建对话框
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Hello");
alert.setHeaderText(null);
alert.setContentText("Hello, World!");
// 显示对话框
alert.showAndWait();
});
// 创建布局并将按钮添加到布局中
StackPane layout = new StackPane();
layout.getChildren().add(button);
// 创建场景并将布局设置为场景的根节点
Scene scene = new Scene(layout, 300, 200);
// 将场景设置到舞台
primaryStage.setScene(scene);
// 显示舞台
primaryStage.show();
}
}