package homein;
|
|
import denglu.UserChuShiHua;
|
import gecaoji.Device;
|
import chuankou.SerialPortAutoConnector;
|
import chuankou.SerialPortNativeLoader;
|
import set.Setsys;
|
import udpdell.UDPServer;
|
import denglu.Denglu;
|
import java.awt.EventQueue;
|
import javax.swing.JOptionPane;
|
|
public class Homein {
|
public static void main(String[] args) {
|
// 检查程序是否已经运行
|
if (WenJianSuo.isAlreadyRunning()) {
|
JOptionPane.showMessageDialog(null,
|
"程序已经在运行中!\n不能同时打开多个实例。",
|
"警告",
|
JOptionPane.WARNING_MESSAGE);
|
System.exit(0);
|
return;
|
}
|
|
// 添加关闭钩子,确保程序退出时释放锁
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
WenJianSuo.releaseLock();
|
}));
|
|
try {
|
SerialPortNativeLoader.ensureLibraryPresent();
|
// 初始化数据
|
UserChuShiHua.initialize();
|
|
Setsys setsys = new Setsys();
|
setsys.initializeFromProperties();
|
Device.initializeActiveDevice(setsys.getMowerId());
|
|
UDPServer.startAsync();//启动数据接收线程
|
// SerialPortAutoConnector.initialize();//启动串口自动连接
|
|
// 显示初始数据
|
System.out.println("初始用户名: " + UserChuShiHua.getProperty("userName"));
|
System.out.println("初始密码: " + UserChuShiHua.getProperty("password"));
|
|
// 启动登录界面
|
startLoginInterface();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
JOptionPane.showMessageDialog(null,
|
"程序启动失败: " + e.getMessage(),
|
"错误",
|
JOptionPane.ERROR_MESSAGE);
|
}
|
}
|
|
private static void startLoginInterface() {
|
// 在EDT中启动登录界面
|
EventQueue.invokeLater(() -> {
|
try {
|
new Denglu().setVisible(true);
|
} catch (Exception e) {
|
e.printStackTrace();
|
JOptionPane.showMessageDialog(null,
|
"登录界面启动失败: " + e.getMessage(),
|
"错误",
|
JOptionPane.ERROR_MESSAGE);
|
}
|
});
|
}
|
}
|