Jelajahi Sumber

优化: 配置页面

张田野 1 Minggu lalu
induk
melakukan
163cc49a81
2 mengubah file dengan 487 tambahan dan 16 penghapusan
  1. 137 6
      src/com/mes/ui/GunConfigFrame.java
  2. 350 10
      src/com/mes/ui/MesClient.java

+ 137 - 6
src/com/mes/ui/GunConfigFrame.java

@@ -10,7 +10,7 @@ import java.util.regex.Pattern;
 
 /**
  * 工位 + 拉铆枪配置页。
- * 启动时弹出一次进入登录;登录后也可从「设置」菜单再次打开修改。
+ * 首次无库时启动弹窗;登录后可从「设置」打开,改颗数/枪IP需密码。
  */
 public class GunConfigFrame extends JFrame {
 
@@ -18,6 +18,7 @@ public class GunConfigFrame extends JFrame {
             "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
     /** 工位号:OP080 或 OP080A */
     private static final Pattern OPRNO_PATTERN = Pattern.compile("^OP\\d{3}[A-Z]?$");
+    public static final String SETTING_PASSWORD = "503833";
 
     /** true=启动进入登录前;false=登录后修改配置 */
     private final boolean startupMode;
@@ -29,6 +30,10 @@ public class GunConfigFrame extends JFrame {
     private JTextField gunANumTxt;
     private JTextField gunBIpTxt;
     private JTextField gunBNumTxt;
+    private JPasswordField pwdTxt;
+    private JButton unlockBtn;
+    private JLabel lockTip;
+    private boolean gunFieldsUnlocked = false;
 
     public GunConfigFrame() {
         this(true);
@@ -36,7 +41,7 @@ public class GunConfigFrame extends JFrame {
 
     public GunConfigFrame(boolean startupMode) {
         this.startupMode = startupMode;
-        setTitle((startupMode ? "启动配置" : "工位/枪配置") + " - "
+        setTitle((startupMode ? "首次初始化配置" : "工位/枪配置") + " - "
                 + nullToEmpty(MesClient.mes_gw) + " " + nullToEmpty(MesClient.mes_gw_des));
         setDefaultCloseOperation(startupMode ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE);
         setResizable(false);
@@ -50,7 +55,7 @@ public class GunConfigFrame extends JFrame {
         root.setBackground(new Color(245, 247, 250));
         setContentPane(root);
 
-        JLabel title = new JLabel(startupMode ? "启动配置" : "工位 / 枪配置", SwingConstants.CENTER);
+        JLabel title = new JLabel(startupMode ? "首次初始化配置" : "工位 / 枪配置", SwingConstants.CENTER);
         title.setFont(new Font("微软雅黑", Font.BOLD, 28));
         title.setForeground(new Color(33, 37, 41));
         root.add(title, BorderLayout.NORTH);
@@ -61,6 +66,11 @@ public class GunConfigFrame extends JFrame {
         center.add(buildStationPanel());
         center.add(Box.createVerticalStrut(16));
 
+        if (!startupMode) {
+            center.add(buildPasswordPanel());
+            center.add(Box.createVerticalStrut(12));
+        }
+
         JPanel guns = new JPanel(new GridLayout(1, 2, 20, 0));
         guns.setOpaque(false);
         guns.setAlignmentX(Component.LEFT_ALIGNMENT);
@@ -97,8 +107,8 @@ public class GunConfigFrame extends JFrame {
         }
 
         JLabel tip = new JLabel(startupMode
-                ? "工位与枪参数均可修改,保存后写入本地配置"
-                : "修改服务器IP/枪IP后会重新连接PLC;工位号变更后建议重连MES");
+                ? "首次无本地数据库时需配置,保存后写入本地配置"
+                : "改颗数/枪IP需先输入密码解锁;改服务器IP/枪IP后会重连PLC");
         tip.setFont(new Font("微软雅黑", Font.PLAIN, 13));
         tip.setForeground(new Color(108, 117, 125));
 
@@ -108,9 +118,13 @@ public class GunConfigFrame extends JFrame {
         south.add(tip, BorderLayout.SOUTH);
         root.add(south, BorderLayout.SOUTH);
 
+        if (!startupMode) {
+            setGunFieldsEditable(false);
+        }
+
         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
         int width = 720;
-        int height = 520;
+        int height = startupMode ? 520 : 600;
         setBounds((d.width - width) / 2, (d.height - height) / 2 - 40, width, height);
     }
 
@@ -121,6 +135,117 @@ public class GunConfigFrame extends JFrame {
         frame.toFront();
     }
 
+    private JPanel buildPasswordPanel() {
+        JPanel panel = new JPanel(new GridBagLayout());
+        panel.setBackground(Color.WHITE);
+        panel.setAlignmentX(Component.LEFT_ALIGNMENT);
+        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 100));
+        panel.setBorder(BorderFactory.createCompoundBorder(
+                BorderFactory.createTitledBorder(
+                        BorderFactory.createLineBorder(new Color(206, 212, 218)),
+                        "改颗数 / 枪IP 需解锁",
+                        TitledBorder.LEFT,
+                        TitledBorder.TOP,
+                        new Font("微软雅黑", Font.BOLD, 16),
+                        new Color(52, 58, 64)),
+                new EmptyBorder(8, 16, 8, 16)));
+
+        GridBagConstraints lc = new GridBagConstraints();
+        lc.gridx = 0;
+        lc.gridy = 0;
+        lc.anchor = GridBagConstraints.EAST;
+        lc.insets = new Insets(4, 4, 4, 8);
+        JLabel pwdLabel = new JLabel("配置密码:");
+        pwdLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
+        panel.add(pwdLabel, lc);
+
+        GridBagConstraints fc = new GridBagConstraints();
+        fc.gridx = 1;
+        fc.gridy = 0;
+        fc.fill = GridBagConstraints.HORIZONTAL;
+        fc.weightx = 1;
+        fc.insets = new Insets(4, 0, 4, 8);
+        pwdTxt = new JPasswordField(16);
+        pwdTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
+        pwdTxt.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                unlockGunFields();
+            }
+        });
+        panel.add(pwdTxt, fc);
+
+        GridBagConstraints bc = new GridBagConstraints();
+        bc.gridx = 2;
+        bc.gridy = 0;
+        bc.insets = new Insets(4, 0, 4, 4);
+        unlockBtn = new JButton("解锁");
+        unlockBtn.setFont(new Font("微软雅黑", Font.PLAIN, 15));
+        unlockBtn.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                unlockGunFields();
+            }
+        });
+        panel.add(unlockBtn, bc);
+
+        GridBagConstraints tc = new GridBagConstraints();
+        tc.gridx = 1;
+        tc.gridy = 1;
+        tc.gridwidth = 2;
+        tc.anchor = GridBagConstraints.WEST;
+        tc.insets = new Insets(0, 0, 4, 4);
+        lockTip = new JLabel("请先输入密码解锁后再修改枪IP / 颗数");
+        lockTip.setFont(new Font("微软雅黑", Font.PLAIN, 13));
+        lockTip.setForeground(new Color(108, 117, 125));
+        panel.add(lockTip, tc);
+        return panel;
+    }
+
+    private void setGunFieldsEditable(boolean editable) {
+        gunFieldsUnlocked = editable;
+        if (gunAIpTxt != null) {
+            gunAIpTxt.setEditable(editable);
+        }
+        if (gunANumTxt != null) {
+            gunANumTxt.setEditable(editable);
+        }
+        if (gunBIpTxt != null) {
+            gunBIpTxt.setEditable(editable);
+        }
+        if (gunBNumTxt != null) {
+            gunBNumTxt.setEditable(editable);
+        }
+        if (pwdTxt != null) {
+            pwdTxt.setEnabled(!editable);
+        }
+        if (unlockBtn != null) {
+            unlockBtn.setEnabled(!editable);
+            unlockBtn.setText(editable ? "已解锁" : "解锁");
+        }
+        if (lockTip != null) {
+            lockTip.setText(editable
+                    ? "已解锁,可修改枪IP / 颗数后保存"
+                    : "请先输入密码解锁后再修改枪IP / 颗数");
+            lockTip.setForeground(editable ? new Color(40, 167, 69) : new Color(108, 117, 125));
+        }
+    }
+
+    private void unlockGunFields() {
+        if (pwdTxt == null) {
+            return;
+        }
+        String pwd = new String(pwdTxt.getPassword()).trim();
+        if (!SETTING_PASSWORD.equals(pwd)) {
+            JOptionPane.showMessageDialog(this, "密码错误", "提示", JOptionPane.WARNING_MESSAGE);
+            pwdTxt.setText("");
+            pwdTxt.requestFocusInWindow();
+            return;
+        }
+        setGunFieldsEditable(true);
+        pwdTxt.setText("");
+    }
+
     private JPanel buildStationPanel() {
         JPanel panel = new JPanel(new GridBagLayout());
         panel.setBackground(Color.WHITE);
@@ -280,6 +405,12 @@ public class GunConfigFrame extends JFrame {
         }
 
         boolean gunIpChanged = !aIp.equals(MesClient.plcAIp) || !bIp.equals(MesClient.plcBIp);
+        boolean gunNumChanged = aNum != MesClient.aSetNum || bNum != MesClient.bSetNum;
+        if (!startupMode && (gunIpChanged || gunNumChanged) && !gunFieldsUnlocked) {
+            JOptionPane.showMessageDialog(this, "请先输入密码解锁后再修改枪IP / 颗数",
+                    "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
 
         MesClient.mes_gw = gw;
         MesClient.mes_gw_des = gwDes;

+ 350 - 10
src/com/mes/ui/MesClient.java

@@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.List;
 import java.util.Timer;
+import java.util.regex.Pattern;
 
 public class MesClient extends JFrame {
 
@@ -99,6 +100,23 @@ public class MesClient extends JFrame {
     public static final String GUN_CONFIG_FILE = "gun_config.properties";
     public static final String MES_LOCAL_CONFIG_FILE = "mes_local.properties";
     public static final String MES_DB_FILE = "mes_db.db";
+    public static final String SETTING_PASSWORD = "503833";
+    private static final Pattern IP_PATTERN = Pattern.compile(
+            "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
+    private static final Pattern OPRNO_PATTERN = Pattern.compile("^OP\\d{3}[A-Z]?$");
+
+    public static JTextField cfgGwTxt;
+    public static JTextField cfgGwDesTxt;
+    public static JTextField cfgServerIpTxt;
+    public static JTextField cfgGunAIpTxt;
+    public static JTextField cfgGunANumTxt;
+    public static JTextField cfgGunBIpTxt;
+    public static JTextField cfgGunBNumTxt;
+    public static JPasswordField cfgPwdTxt;
+    public static JButton cfgUnlockBtn;
+    public static JButton cfgSaveBtn;
+    public static JLabel cfgLockTip;
+    public static boolean settingUnlocked = false;
 
     public static Timer cjTimer;
 
@@ -141,9 +159,13 @@ public class MesClient extends JFrame {
                     mesClientFrame = new MesClient();
                     mesClientFrame.setVisible(false);
 
-                    // 先进入拉铆枪配置页
-                    GunConfigFrame gunConfigFrame = new GunConfigFrame();
-                    gunConfigFrame.setVisible(true);
+                    // 只有第一次(本地尚无工位配置且无数据库)登录前弹配置;之后直接进登录
+                    if (needFirstSetup()) {
+                        GunConfigFrame gunConfigFrame = new GunConfigFrame();
+                        gunConfigFrame.setVisible(true);
+                    } else {
+                        enterLoginReady();
+                    }
 
                 }catch (Exception e){
                     e.printStackTrace();
@@ -211,6 +233,11 @@ public class MesClient extends JFrame {
         return new File(System.getProperty("user.dir"), MES_DB_FILE);
     }
 
+    /** 首次进入:本地既没有 mes_local.properties 也没有 mes_db.db 才弹登录前配置 */
+    public static boolean needFirstSetup() {
+        return !getMesLocalConfigFile().exists() && !getMesDbFile().exists();
+    }
+
     /** 从本地 mes_local.properties 覆盖工位号/工位名称/服务器IP(若存在) */
     public static void loadMesLocalConfig() {
         File file = getMesLocalConfigFile();
@@ -301,6 +328,316 @@ public class MesClient extends JFrame {
         }
     }
 
+    public static void refreshSettingFields() {
+        if (cfgGwTxt != null) {
+            cfgGwTxt.setText(mes_gw == null ? "" : mes_gw);
+        }
+        if (cfgGwDesTxt != null) {
+            cfgGwDesTxt.setText(mes_gw_des == null ? "" : mes_gw_des);
+        }
+        if (cfgServerIpTxt != null) {
+            cfgServerIpTxt.setText(mes_server_ip == null ? "" : mes_server_ip);
+        }
+        if (cfgGunAIpTxt != null) {
+            cfgGunAIpTxt.setText(plcAIp == null ? "" : plcAIp);
+        }
+        if (cfgGunANumTxt != null) {
+            cfgGunANumTxt.setText(String.valueOf(aSetNum));
+        }
+        if (cfgGunBIpTxt != null) {
+            cfgGunBIpTxt.setText(plcBIp == null ? "" : plcBIp);
+        }
+        if (cfgGunBNumTxt != null) {
+            cfgGunBNumTxt.setText(String.valueOf(bSetNum));
+        }
+    }
+
+    public static void setSettingFieldsEditable(boolean editable) {
+        if (cfgGwTxt != null) {
+            cfgGwTxt.setEditable(editable);
+        }
+        if (cfgGwDesTxt != null) {
+            cfgGwDesTxt.setEditable(editable);
+        }
+        if (cfgServerIpTxt != null) {
+            cfgServerIpTxt.setEditable(editable);
+        }
+        if (cfgGunAIpTxt != null) {
+            cfgGunAIpTxt.setEditable(editable);
+        }
+        if (cfgGunANumTxt != null) {
+            cfgGunANumTxt.setEditable(editable);
+        }
+        if (cfgGunBIpTxt != null) {
+            cfgGunBIpTxt.setEditable(editable);
+        }
+        if (cfgGunBNumTxt != null) {
+            cfgGunBNumTxt.setEditable(editable);
+        }
+        if (cfgSaveBtn != null) {
+            cfgSaveBtn.setEnabled(editable);
+        }
+        if (cfgPwdTxt != null) {
+            cfgPwdTxt.setEnabled(!editable);
+        }
+        if (cfgUnlockBtn != null) {
+            cfgUnlockBtn.setEnabled(!editable);
+            cfgUnlockBtn.setText(editable ? "已解锁" : "解锁");
+        }
+        if (cfgLockTip != null) {
+            cfgLockTip.setText(editable
+                    ? "已解锁,可修改后点击保存;离开本页会重新锁定"
+                    : "请先输入密码解锁后再修改配置");
+            cfgLockTip.setForeground(editable ? new Color(40, 167, 69) : new Color(108, 117, 125));
+        }
+    }
+
+    public static void lockSettingPanel() {
+        settingUnlocked = false;
+        if (cfgPwdTxt != null) {
+            cfgPwdTxt.setText("");
+        }
+        setSettingFieldsEditable(false);
+    }
+
+    public static void unlockSettingFromUi() {
+        if (cfgPwdTxt == null) {
+            return;
+        }
+        String pwd = new String(cfgPwdTxt.getPassword()).trim();
+        if (!SETTING_PASSWORD.equals(pwd)) {
+            JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示", JOptionPane.WARNING_MESSAGE);
+            cfgPwdTxt.setText("");
+            cfgPwdTxt.requestFocusInWindow();
+            return;
+        }
+        settingUnlocked = true;
+        setSettingFieldsEditable(true);
+        cfgPwdTxt.setText("");
+    }
+
+    public static void saveSettingFromUi() {
+        if (!settingUnlocked) {
+            JOptionPane.showMessageDialog(mesClientFrame, "请先输入密码解锁", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        if (work_status == 1) {
+            setMenuStatus("加工中,不能修改配置", -1);
+            return;
+        }
+        String gw = cfgGwTxt.getText().trim().toUpperCase();
+        String gwDes = cfgGwDesTxt.getText().trim();
+        String serverIp = cfgServerIpTxt.getText().trim();
+        String aIp = cfgGunAIpTxt.getText().trim();
+        String bIp = cfgGunBIpTxt.getText().trim();
+        String aNumStr = cfgGunANumTxt.getText().trim();
+        String bNumStr = cfgGunBNumTxt.getText().trim();
+
+        if (gw.isEmpty() || !OPRNO_PATTERN.matcher(gw).matches()) {
+            JOptionPane.showMessageDialog(mesClientFrame, "工位号格式不正确,应为 OP080 或 OP080A",
+                    "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        if (gwDes.isEmpty()) {
+            JOptionPane.showMessageDialog(mesClientFrame, "请输入工位名称", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        if (!IP_PATTERN.matcher(serverIp).matches()) {
+            JOptionPane.showMessageDialog(mesClientFrame, "服务器 IP 格式不正确", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        if (!IP_PATTERN.matcher(aIp).matches()) {
+            JOptionPane.showMessageDialog(mesClientFrame, "A枪 IP 格式不正确", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        if (!IP_PATTERN.matcher(bIp).matches()) {
+            JOptionPane.showMessageDialog(mesClientFrame, "B枪 IP 格式不正确", "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        short aNum;
+        short bNum;
+        try {
+            aNum = Short.parseShort(aNumStr);
+            bNum = Short.parseShort(bNumStr);
+            if (aNum <= 0 || bNum <= 0) {
+                throw new NumberFormatException("<=0");
+            }
+        } catch (Exception ex) {
+            JOptionPane.showMessageDialog(mesClientFrame, "打铆颗数必须是大于 0 的整数",
+                    "提示", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+
+        boolean gunIpChanged = !aIp.equals(plcAIp) || !bIp.equals(plcBIp);
+        boolean serverIpChanged = !serverIp.equals(mes_server_ip);
+        mes_gw = gw;
+        mes_gw_des = gwDes;
+        mes_server_ip = serverIp;
+        plcAIp = aIp;
+        plcBIp = bIp;
+        aSetNum = aNum;
+        bSetNum = bNum;
+
+        if (!saveMesLocalConfig()) {
+            return;
+        }
+        saveGunConfig();
+        if (mesClientFrame != null) {
+            mesClientFrame.setTitle("MES系统客户端:" + mes_gw + "- " + mes_gw_des);
+        }
+        try {
+            if (gunIpChanged) {
+                initPlc();
+            }
+            String tip = "配置已保存:A=" + plcAIp + "/" + aSetNum + " B=" + plcBIp + "/" + bSetNum;
+            if (serverIpChanged) {
+                tip += ";服务器IP已改,请菜单「设置→重连MES」";
+            }
+            setMenuStatus(tip, 0);
+        } catch (Exception e) {
+            setMenuStatus("配置已保存,PLC同步失败:" + e.getMessage(), -1);
+        }
+    }
+
+    public static void buildSettingPanel() {
+        JPanel panel = new JPanel(null);
+        JScrollPane scroll = new JScrollPane(panel);
+
+        JLabel title = new JLabel("工位 / 枪配置", SwingConstants.CENTER);
+        title.setFont(new Font("微软雅黑", Font.BOLD, 24));
+        title.setBounds(80, 20, 700, 40);
+        panel.add(title);
+
+        JLabel pwdLabel = new JLabel("配置密码:");
+        pwdLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        pwdLabel.setBounds(160, 70, 120, 36);
+        panel.add(pwdLabel);
+        cfgPwdTxt = new JPasswordField();
+        cfgPwdTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgPwdTxt.setBounds(290, 70, 200, 36);
+        cfgPwdTxt.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                unlockSettingFromUi();
+            }
+        });
+        panel.add(cfgPwdTxt);
+
+        cfgUnlockBtn = new JButton("解锁");
+        cfgUnlockBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgUnlockBtn.setBounds(500, 70, 110, 36);
+        cfgUnlockBtn.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                unlockSettingFromUi();
+            }
+        });
+        panel.add(cfgUnlockBtn);
+
+        cfgLockTip = new JLabel("请先输入密码解锁后再修改配置");
+        cfgLockTip.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        cfgLockTip.setForeground(new Color(108, 117, 125));
+        cfgLockTip.setBounds(290, 108, 420, 24);
+        panel.add(cfgLockTip);
+
+        JLabel gwLabel = new JLabel("工位号:");
+        gwLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        gwLabel.setBounds(160, 150, 120, 36);
+        panel.add(gwLabel);
+        cfgGwTxt = new JTextField();
+        cfgGwTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgGwTxt.setBounds(290, 150, 320, 36);
+        panel.add(cfgGwTxt);
+
+        JLabel gwDesLabel = new JLabel("工位名称:");
+        gwDesLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        gwDesLabel.setBounds(160, 200, 120, 36);
+        panel.add(gwDesLabel);
+        cfgGwDesTxt = new JTextField();
+        cfgGwDesTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgGwDesTxt.setBounds(290, 200, 320, 36);
+        panel.add(cfgGwDesTxt);
+
+        JLabel serverLabel = new JLabel("服务器IP:");
+        serverLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        serverLabel.setBounds(160, 250, 120, 36);
+        panel.add(serverLabel);
+        cfgServerIpTxt = new JTextField();
+        cfgServerIpTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgServerIpTxt.setBounds(290, 250, 320, 36);
+        panel.add(cfgServerIpTxt);
+
+        JLabel gunAIpLabel = new JLabel("A枪IP:");
+        gunAIpLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        gunAIpLabel.setBounds(160, 310, 120, 36);
+        panel.add(gunAIpLabel);
+        cfgGunAIpTxt = new JTextField();
+        cfgGunAIpTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgGunAIpTxt.setBounds(290, 310, 320, 36);
+        panel.add(cfgGunAIpTxt);
+
+        JLabel gunANumLabel = new JLabel("A枪颗数:");
+        gunANumLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        gunANumLabel.setBounds(160, 360, 120, 36);
+        panel.add(gunANumLabel);
+        cfgGunANumTxt = new JTextField();
+        cfgGunANumTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgGunANumTxt.setBounds(290, 360, 320, 36);
+        panel.add(cfgGunANumTxt);
+
+        JLabel gunBIpLabel = new JLabel("B枪IP:");
+        gunBIpLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        gunBIpLabel.setBounds(160, 410, 120, 36);
+        panel.add(gunBIpLabel);
+        cfgGunBIpTxt = new JTextField();
+        cfgGunBIpTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgGunBIpTxt.setBounds(290, 410, 320, 36);
+        panel.add(cfgGunBIpTxt);
+
+        JLabel gunBNumLabel = new JLabel("B枪颗数:");
+        gunBNumLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        gunBNumLabel.setBounds(160, 460, 120, 36);
+        panel.add(gunBNumLabel);
+        cfgGunBNumTxt = new JTextField();
+        cfgGunBNumTxt.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        cfgGunBNumTxt.setBounds(290, 460, 320, 36);
+        panel.add(cfgGunBNumTxt);
+
+        cfgSaveBtn = new JButton("保存配置");
+        cfgSaveBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        cfgSaveBtn.setBounds(290, 530, 180, 48);
+        cfgSaveBtn.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                saveSettingFromUi();
+            }
+        });
+        panel.add(cfgSaveBtn);
+
+        JLabel tip = new JLabel("保存到本地配置;改枪IP会重连PLC,改服务器IP后请重连MES");
+        tip.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        tip.setForeground(new Color(108, 117, 125));
+        tip.setBounds(120, 600, 700, 30);
+        panel.add(tip);
+
+        panel.setPreferredSize(new Dimension(900, 660));
+        refreshSettingFields();
+        lockSettingPanel();
+        tabbedPane.addTab("软件设置", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), scroll, null);
+    }
+
+    public static void selectSettingTab() {
+        if (tabbedPane == null) {
+            return;
+        }
+        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
+            if ("软件设置".equals(tabbedPane.getTitleAt(i))) {
+                tabbedPane.setSelectedIndex(i);
+                return;
+            }
+        }
+    }
+
     public static Timer cjTimerText;
     public static void textFocus() {
         if(cjTimerText!=null) {
@@ -887,7 +1224,7 @@ public class MesClient extends JFrame {
             @Override
             public void mousePressed(MouseEvent e) {
                 super.mouseClicked(e);
-                GunConfigFrame.openForEdit();
+                selectSettingTab();
             }
         });
         settingMenu.add(gunConfigMenu);
@@ -1136,23 +1473,26 @@ public class MesClient extends JFrame {
 
         tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
 
-
         indexPanelB = new JPanel();
         searchScrollPane = new JScrollPane(indexPanelB);
         indexPanelB.setLayout(null);
 
 		tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
 
+        buildSettingPanel();
+
 
 		tabbedPane.addChangeListener(new ChangeListener() {
             @Override
             public void stateChanged(ChangeEvent e) {
-                JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
-                int selectedIndex = tabbedPane.getSelectedIndex();
+                JTabbedPane pane = (JTabbedPane) e.getSource();
+                int selectedIndex = pane.getSelectedIndex();
                 System.out.println("selectedIndex:"+selectedIndex);
-
-                if(selectedIndex == 1){
-
+                if (selectedIndex >= 0 && "软件设置".equals(pane.getTitleAt(selectedIndex))) {
+                    refreshSettingFields();
+                    lockSettingPanel();
+                } else if (settingUnlocked) {
+                    lockSettingPanel();
                 }
             }
         });