| | |
| | | |
| | | import homein.WenJianSuo; |
| | | import ui.UIConfig; |
| | | import zhuye.Shouye; |
| | | import gecaoji.Device; |
| | | import chuankou.SerialPortNativeLoader; |
| | | import set.Setsys; |
| | | import udpdell.UDPServer; |
| | | import user.Usrdell; |
| | | import Mqttmessage.Client; |
| | | import javax.swing.*; |
| | | import java.awt.*; |
| | | import java.awt.event.*; |
| | |
| | | // 忘记密码点击事件 |
| | | forgotPassword.addMouseListener(new MouseAdapter() { |
| | | public void mouseClicked(MouseEvent e) { |
| | | JOptionPane.showMessageDialog(Denglu.this, |
| | | "请联系管理员重置密码", |
| | | "忘记密码", |
| | | JOptionPane.INFORMATION_MESSAGE); |
| | | new user.ZhaohuiMima(Denglu.this).setVisible(true); |
| | | } |
| | | }); |
| | | |
| | |
| | | usernameField.setText(""); |
| | | } |
| | | |
| | | // 如果密码为-1,清空密码框 |
| | | String savedPassword = UserChuShiHua.getProperty("password"); |
| | | if (savedPassword != null && savedPassword.equals("-1")) { |
| | | passwordField.setText(""); |
| | | // 加载记住我状态 |
| | | String rememberPwd = UserChuShiHua.getProperty("rememberPassword"); |
| | | boolean isRemember = "1".equals(rememberPwd); |
| | | rememberMe.setSelected(isRemember); |
| | | |
| | | // 如果记住我被选中,填充密码 |
| | | if (isRemember) { |
| | | String savedPassword = UserChuShiHua.getProperty("password"); |
| | | if (savedPassword != null && !savedPassword.equals("-1")) { |
| | | passwordField.setText(savedPassword); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // 验证用户名和密码 |
| | | if (validateLogin(username, password)) { |
| | | JOptionPane.showMessageDialog(this, |
| | | "登录成功!", |
| | | "成功", |
| | | JOptionPane.INFORMATION_MESSAGE); |
| | | |
| | | // 更新最后登录时间 |
| | | UserChuShiHua.updateProperty("lastLoginTime", String.valueOf(System.currentTimeMillis())); |
| | | |
| | | // 如果记住我被选中,保存用户名 |
| | | // 保存记住我状态 |
| | | if (rememberMe.isSelected()) { |
| | | UserChuShiHua.updateProperty("rememberPassword", "1"); |
| | | UserChuShiHua.updateProperty("userName", username); |
| | | } else { |
| | | UserChuShiHua.updateProperty("rememberPassword", "0"); |
| | | } |
| | | |
| | | // 这里可以添加跳转到主界面的代码 |
| | | // 关闭登录窗口并打开首页 |
| | | openMainApplication(); |
| | | |
| | | } else { |
| | |
| | | } |
| | | |
| | | private void openMainApplication() { |
| | | // 这里可以打开主应用程序窗口 |
| | | System.out.println("登录成功,准备打开主应用程序..."); |
| | | |
| | | // 演示:3秒后关闭登录窗口 |
| | | Timer timer = new Timer(1000, e -> { |
| | | dispose(); |
| | | System.out.println("登录窗口已关闭,主应用程序已启动"); |
| | | launchMainApp(); |
| | | dispose(); |
| | | } |
| | | |
| | | public static void launchMainApp() { |
| | | System.out.println("准备打开主应用程序..."); |
| | | |
| | | SwingUtilities.invokeLater(() -> { |
| | | JFrame mainFrame = new JFrame("智能割草系统"); |
| | | mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
| | | |
| | | Shouye homePanel = new Shouye(); |
| | | mainFrame.setContentPane(homePanel); |
| | | |
| | | // 设置与登录页面相同的尺寸 |
| | | mainFrame.setSize(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT); |
| | | mainFrame.setMinimumSize(new Dimension(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT)); |
| | | mainFrame.setResizable(false); |
| | | mainFrame.setLocationRelativeTo(null); |
| | | mainFrame.setVisible(true); |
| | | |
| | | System.out.println("主应用程序已启动"); |
| | | |
| | | // 启动后连接MQTT |
| | | new Thread(() -> { |
| | | System.out.println("正在连接MQTT服务器..."); |
| | | Client.lianjiemqqt(); |
| | | }).start(); |
| | | }); |
| | | timer.setRepeats(false); |
| | | timer.start(); |
| | | } |
| | | |
| | | // 注册窗口方法 |
| | |
| | | RegistrationFrame registerFrame = new RegistrationFrame(this, currentLanguageCode); |
| | | registerFrame.setVisible(true); |
| | | } |
| | | |
| | | /** |
| | | * 程序入口点 |
| | | * 集成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(); |
| | | Usrdell.initialize(); // 初始化用户属性 |
| | | |
| | | Setsys setsys = new Setsys(); |
| | | setsys.initializeFromProperties(); |
| | | Device.initializeActiveDevice(setsys.getMowerId()); |
| | | |
| | | UDPServer.startAsync();//启动数据接收线程 |
| | | |
| | | // 显示初始数据 |
| | | System.out.println("初始用户名: " + UserChuShiHua.getProperty("userName")); |
| | | System.out.println("初始密码: " + UserChuShiHua.getProperty("password")); |
| | | |
| | | // 检查是否记住密码,如果是则直接进入主页 |
| | | String rememberPwd = UserChuShiHua.getProperty("rememberPassword"); |
| | | if ("1".equals(rememberPwd)) { |
| | | String storedUser = UserChuShiHua.getProperty("userName"); |
| | | if (storedUser != null && !storedUser.equals("-1")) { |
| | | launchMainApp(); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 启动登录界面 |
| | | EventQueue.invokeLater(() -> { |
| | | try { |
| | | new Denglu().setVisible(true); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | JOptionPane.showMessageDialog(null, |
| | | "登录界面启动失败: " + e.getMessage(), |
| | | "错误", |
| | | JOptionPane.ERROR_MESSAGE); |
| | | } |
| | | }); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | JOptionPane.showMessageDialog(null, |
| | | "程序启动失败: " + e.getMessage(), |
| | | "错误", |
| | | JOptionPane.ERROR_MESSAGE); |
| | | } |
| | | } |
| | | |
| | | } |