张世豪
2 天以前 c9b1d33979b3972fe6a82fa427b4ba9a20989112
src/homein/Homein.java
@@ -1,71 +1,11 @@
package homein;
import denglu.UserChuShiHua;
import gecaoji.Device;
import chuankou.SerialPortAutoConnector;
import set.Setsys;
import udpdell.UDPServer;
import denglu.Denglu;
import javax.swing.JOptionPane;
public class Homein {
    /**
     * 程序入口点 - 已迁移到Denglu类
     * 保留此方法以保持向后兼容性,实际调用Denglu.main
     */
    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 {
                // 初始化数据
                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中启动登录界面
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Denglu().setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null,
                        "登录界面启动失败: " + e.getMessage(),
                        "错误",
                        JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        Denglu.main(args);
    }
}