1. youhua
This commit is contained in:
parent
40e1932f0c
commit
0091075137
|
@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public class CommandUtils {
|
|||
public static void killUsedPort(String port){
|
||||
List<LsofInfo> 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<LsofInfo> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue