From 0091075137712dfe348fc91b22d340a472ee63f1 Mon Sep 17 00:00:00 2001 From: jianguo Date: Wed, 29 May 2024 14:41:24 +0800 Subject: [PATCH] 1. youhua --- src/main/java/org/aohe/Main.java | 9 +++--- .../java/org/aohe/core/swing/NewWindow.java | 29 +++++++++++++------ .../org/aohe/core/utils/CommandUtils.java | 5 +++- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/aohe/Main.java b/src/main/java/org/aohe/Main.java index 9383ddc..8dcebe7 100644 --- a/src/main/java/org/aohe/Main.java +++ b/src/main/java/org/aohe/Main.java @@ -1,13 +1,12 @@ package org.aohe; -import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatDarculaLaf; import lombok.extern.slf4j.Slf4j; import org.aohe.core.sane.utils.SaneSessionUtils; -import org.aohe.core.swing.MainWindow; +import org.aohe.core.swing.NewWindow; import org.aohe.core.utils.CommandUtils; import org.aohe.core.utils.SystemUtils; import org.aohe.core.web.SocketFactory; -import com.formdev.flatlaf.FlatLightLaf; import javax.swing.*; @@ -19,13 +18,13 @@ public class Main { try { //设置窗口主题 //FlatLightLaf.setup(); - UIManager.setLookAndFeel(new FlatDarkLaf()); + UIManager.setLookAndFeel(new FlatDarculaLaf()); } catch (UnsupportedLookAndFeelException e) { throw new RuntimeException(e); } //初始化其他资源 init(); - SwingUtilities.invokeLater(() -> new MainWindow().setVisible(true)); + SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true)); } diff --git a/src/main/java/org/aohe/core/swing/NewWindow.java b/src/main/java/org/aohe/core/swing/NewWindow.java index ba09750..0be6d48 100644 --- a/src/main/java/org/aohe/core/swing/NewWindow.java +++ b/src/main/java/org/aohe/core/swing/NewWindow.java @@ -11,6 +11,8 @@ public class NewWindow extends JFrame { private static JTextArea logTextArea; + private static final JLabel textField = new JLabel(); + public NewWindow() { // 设置窗口标题 setTitle("扫描前端"); @@ -30,7 +32,6 @@ public class NewWindow extends JFrame { private void initializeComponents() { - JLabel textField = new JLabel(); textField.setForeground(Color.GRAY); textField.setText("服务状态:启动中..."); @@ -43,12 +44,16 @@ public class NewWindow extends JFrame { stopButton.addActionListener(e -> { stopButton.setEnabled(false); logTextArea.append("关闭服务中...\n"); - //开个新线程关闭,防止主UI线程卡死 - stopSocket(); - textField.setForeground(Color.RED); - textField.setText("服务状态:关闭"); - //关闭任务 - System.exit(0); + //开个新线程关闭,防止主UI线程卡死 + new Thread( () ->{ + stopSocket(); + //关闭任务 + sleep(1000); + textField.setForeground(Color.RED); + textField.setText("服务状态:关闭"); + sleep(100); + System.exit(0); + } ).start(); }); getContentPane().add(textField, BorderLayout.NORTH); @@ -64,6 +69,8 @@ public class NewWindow extends JFrame { public void initSocket() { if(SocketFactory.start()){ setView("socket 服务启动成功"); + textField.setForeground(Color.GREEN); + textField.setText("服务状态:启动"); }else{ setView("socket 服务启动失败,请检查8997端口是否被占用"); } @@ -104,7 +111,11 @@ public class NewWindow extends JFrame { getContentPane().add(scrollPane, BorderLayout.CENTER); } - public static void main(String[] args) { - SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true)); + public static void sleep(long m){ + try { + Thread.sleep(m); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/org/aohe/core/utils/CommandUtils.java b/src/main/java/org/aohe/core/utils/CommandUtils.java index 955a6e5..616d05e 100644 --- a/src/main/java/org/aohe/core/utils/CommandUtils.java +++ b/src/main/java/org/aohe/core/utils/CommandUtils.java @@ -64,6 +64,7 @@ public class CommandUtils { public static void killUsedPort(String port){ List lsofInfos = findPort(port); for(LsofInfo lsofInfo : lsofInfos){ + log.info(" pro kill begin {}", lsofInfo); destroy(lsofInfo.getPid()); } } @@ -71,12 +72,14 @@ public class CommandUtils { public static List findPort(String port){ String exec = StrUtil.format("lsof -i:{}",port); String s = execForStrUtf8Sudo(exec); + log.info(s); return parseCommandOutput(s); } public static void destroy(String pid){ String exec = StrUtil.format("kill -9 {}",pid); - execForStrUtf8Sudo(exec); + String s = execForStrUtf8Sudo(exec); + log.info(s); } /**