64 lines
1.9 KiB
Java
64 lines
1.9 KiB
Java
package com.fantaibao;
|
|
|
|
import com.fantaibao.config.GlobalConfig;
|
|
import com.fantaibao.page.LoginView;
|
|
import javafx.application.Application;
|
|
import javafx.application.Platform;
|
|
import javafx.scene.image.Image;
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.WindowEvent;
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
@SpringBootApplication
|
|
public class DesktopApplication extends Application {
|
|
|
|
private static ConfigurableApplicationContext applicationContext;
|
|
|
|
public static void main(String[] args) {
|
|
// 设置JavaFX系统属性
|
|
System.setProperty("javafx.application.platform", "egl");
|
|
applicationContext = SpringApplication.run(DesktopApplication.class, args);
|
|
launch(args);
|
|
}
|
|
|
|
@Override
|
|
public void init() throws Exception {
|
|
super.init();
|
|
}
|
|
|
|
@Override
|
|
public void start(Stage primaryStage) {
|
|
// 设置窗口标题
|
|
primaryStage.setTitle("中差评采集工具");
|
|
// 添加窗口关闭事件监听器
|
|
primaryStage.setOnCloseRequest(this::handleCloseEvent);
|
|
// 添加多个尺寸的图标
|
|
GlobalConfig.addIcon(primaryStage);
|
|
// 直接启动登录界面
|
|
new LoginView(primaryStage);
|
|
}
|
|
|
|
@Override
|
|
public void stop() {
|
|
closeApplicationContext();
|
|
}
|
|
|
|
/**
|
|
* 关闭Spring Boot应用上下文
|
|
*/
|
|
public static void closeApplicationContext() {
|
|
if (applicationContext != null && applicationContext.isRunning()) {
|
|
applicationContext.close();
|
|
}
|
|
}
|
|
|
|
private void handleCloseEvent(WindowEvent event) {
|
|
// 关闭Spring Boot应用上下文
|
|
closeApplicationContext();
|
|
// 退出JVM
|
|
Platform.exit();
|
|
System.exit(0);
|
|
}
|
|
} |