在JavaFX中关闭应用程序可以通过调用Platform.exit()方法来实现。这个方法会关闭所有已经打开的窗口并终止JavaFX应用程序。
可以在主类中重写stop()方法,在这个方法中调用Platform.exit()来实现。
如下是一个示例:
public class Main extends Application {
public void start(Stage primaryStage) {
// your code here
@Override
public void stop() {
Platform.exit();
public static void main(String[] args) {
launch(args);
在上面的示例代码中,在主类中重写stop()方法,在这个方法中调用Platform.exit()来关闭程序。