From b315a6943e6c0d6bdf0d5f7565c570d719154d6c Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 17 十二月 2025 14:56:58 +0800
Subject: [PATCH] 新增了障碍物管理页面

---
 src/zhuye/buttonset.java |  128 +++++++++++++++++++++++++++++-------------
 1 files changed, 88 insertions(+), 40 deletions(-)

diff --git a/src/zhuye/buttonset.java b/src/zhuye/buttonset.java
index 50bad9c..2d6df18 100644
--- a/src/zhuye/buttonset.java
+++ b/src/zhuye/buttonset.java
@@ -1,70 +1,118 @@
 package zhuye;
 
+import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Font;
-
-import javax.swing.BorderFactory;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.RoundRectangle2D;
 import javax.swing.JButton;
+import javax.swing.border.EmptyBorder;
 
 /**
- * 鎻愪緵缁熶竴鎸夐挳鏍峰紡鐨勫伐鍘傛柟娉曘��
+ * 鎻愪緵缁熶竴鎸夐挳鏍峰紡鐨勫伐鍘傛柟娉曪紙缇庡寲鐗堬級銆�
+ * 椋庢牸涓� ObstacleManagementPage 淇濇寔涓�鑷达細鍦嗚銆佹墎骞冲寲銆佹姉閿娇銆�
  */
 public final class buttonset {
+    
+    // 榛樿鎸夐挳灏哄
     private static final Dimension DEFAULT_SIZE = new Dimension(90, 36);
+    // 鍦嗚鍗婂緞
+    private static final int CORNER_RADIUS = 8;
 
     private buttonset() {
         // 宸ュ叿绫讳笉闇�瑕佸疄渚嬪寲
     }
 
     /**
-     * 鍒涘缓甯︽湁缁熶竴鏍峰紡鐨勬寜閽紝渚涘涓晫闈㈠鐢ㄣ��
+     * 鍒涘缓甯︽湁鐜颁唬鍖栫粺涓�鏍峰紡鐨勬寜閽紙鍦嗚銆佹墎骞抽鏍硷級銆�
      *
      * @param text 鎸夐挳鏄剧ず鏂囨湰
-     * @param backgroundColor 鎸夐挳鑳屾櫙鑹�
+     * @param backgroundColor 鎸夐挳涓昏壊璋冿紙濡傛灉涓簄ull锛岄粯璁や娇鐢ㄧ伆钃濊壊锛�
      * @return 宸插簲鐢ㄦ牱寮忕殑 JButton
      */
     public static JButton createStyledButton(String text, Color backgroundColor) {
+        // 纭畾鍩虹棰滆壊锛屽鏋滄湭鎸囧畾鍒欎娇鐢ㄩ粯璁ょ殑閽㈣摑鑹�
         final Color baseColor = backgroundColor != null ? backgroundColor : new Color(70, 130, 180);
 
-        JButton button = new JButton(text);
+        // 鍒涘缓鑷畾涔夌粯鍒剁殑鎸夐挳
+        JButton button = new JButton(text) {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            protected void paintComponent(Graphics g) {
+                Graphics2D g2 = (Graphics2D) g.create();
+                // 寮�鍚姉閿娇锛屼娇鍦嗚鍜屾枃瀛楁洿骞虫粦
+                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+                // 鑾峰彇鎸夐挳鐘舵��
+                boolean isPressed = getModel().isPressed();
+                boolean isRollover = getModel().isRollover();
+                int w = getWidth();
+                int h = getHeight();
+
+                // 璁$畻褰撳墠鑳屾櫙鑹�
+                if (isPressed) {
+                    g2.setColor(baseColor.darker()); // 鎸変笅鍙樻繁
+                } else if (isRollover) {
+                    // 鎮仠鏃剁◢寰�忔槑鎴栧彉浜紝澧炲姞浜や簰鎰�
+                    g2.setColor(new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 220)); 
+                } else {
+                    g2.setColor(baseColor); // 姝e父棰滆壊
+                }
+
+                // 缁樺埗鍦嗚鐭╁舰鑳屾櫙
+                g2.fill(new RoundRectangle2D.Double(0, 0, w, h, CORNER_RADIUS, CORNER_RADIUS));
+
+                // 濡傛灉闇�瑕佸湪鎸変笅鏃舵湁杞诲井鐨勮竟妗嗘晥鏋滐紙鍙�夛紝澧炲姞绔嬩綋鎰燂級
+                if (isPressed) {
+                    g2.setColor(new Color(0, 0, 0, 30));
+                    g2.draw(new RoundRectangle2D.Double(0.5, 0.5, w - 1, h - 1, CORNER_RADIUS, CORNER_RADIUS));
+                }
+
+                // 缁樺埗鏂囧瓧
+                g2.setColor(Color.WHITE);
+                g2.setFont(getFont());
+                FontMetrics fm = g2.getFontMetrics();
+                
+                // 绮剧‘璁$畻鏂囧瓧灞呬腑浣嶇疆
+                int textX = (w - fm.stringWidth(getText())) / 2;
+                // 娉ㄦ剰锛歽鍧愭爣鏄熀绾夸綅缃紝闇�瑕佸姞涓� Ascent 骞跺噺鍘婚珮搴︾殑涓�鍗�
+                int textY = (h - fm.getHeight()) / 2 + fm.getAscent();
+                
+                g2.drawString(getText(), textX, textY);
+
+                g2.dispose();
+            }
+        };
+
+        // 鍩虹灞炴�ц缃�
         button.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
-        button.setBackground(baseColor);
         button.setForeground(Color.WHITE);
-        button.setFocusPainted(false);
-        button.setBorder(BorderFactory.createEmptyBorder(8, 18, 8, 18));
+        button.setFocusPainted(false);      // 鍘婚櫎鐒︾偣铏氱嚎妗�
+        button.setContentAreaFilled(false); // 鍘婚櫎榛樿鑳屾櫙缁樺埗锛堢敱paintComponent鎺ョ锛�
+        button.setBorderPainted(false);     // 鍘婚櫎榛樿杈规
+        button.setCursor(new Cursor(Cursor.HAND_CURSOR)); // 榧犳爣鍙樻垚鎵嬪瀷
+        
+        // 璁剧疆鍐呰竟璺濓紙铏界劧涓昏鐢眕aintComponent鎺у埗锛屼絾瀵瑰竷灞�璁$畻鏈夊府鍔╋級
+        button.setBorder(new EmptyBorder(8, 18, 8, 18));
 
-    Dimension preferred = button.getPreferredSize();
-    int width = Math.max(preferred.width, DEFAULT_SIZE.width);
-    int height = Math.max(preferred.height, DEFAULT_SIZE.height);
-    Dimension adjustedSize = new Dimension(width, height);
-
-    button.setPreferredSize(adjustedSize);
-    button.setMinimumSize(new Dimension(DEFAULT_SIZE.width, DEFAULT_SIZE.height));
-    button.setMaximumSize(adjustedSize);
-
-        button.addMouseListener(new java.awt.event.MouseAdapter() {
-            @Override
-            public void mouseEntered(java.awt.event.MouseEvent event) {
-                button.setBackground(brightenColor(baseColor));
-            }
-
-            @Override
-            public void mouseExited(java.awt.event.MouseEvent event) {
-                button.setBackground(baseColor);
-            }
-        });
+        // 灏哄璁$畻閫昏緫
+        Dimension preferred = button.getPreferredSize();
+        // 纭繚瀹藉害涓嶅皬浜庨粯璁ゅ�硷紝涓旀牴鎹枃瀛楅暱搴﹁嚜閫傚簲
+        int width = Math.max(preferred.width + 20, DEFAULT_SIZE.width); 
+        int height = Math.max(preferred.height, DEFAULT_SIZE.height);
+        
+        Dimension finalSize = new Dimension(width, height);
+        button.setPreferredSize(finalSize);
+        button.setMinimumSize(DEFAULT_SIZE);
+        button.setMaximumSize(finalSize); // 闃叉鍦ㄦ煇浜涘竷灞�涓杩囧害鎷変几
 
         return button;
     }
-
-    private static Color brightenColor(Color color) {
-        if (color == null) {
-            return new Color(200, 200, 200);
-        }
-        int r = Math.min(255, color.getRed() + 30);
-        int g = Math.min(255, color.getGreen() + 30);
-        int b = Math.min(255, color.getBlue() + 30);
-        return new Color(r, g, b);
-    }
-}
+}
\ No newline at end of file

--
Gitblit v1.10.0