张世豪
2025-12-02 6799351be12deb2f713f2c0a2b4c467a6d1098c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package zhuye;
 
import ui.UIConfig;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class RemoteControlDialog extends JDialog {
    private final Color THEME_COLOR;
    
    public RemoteControlDialog(Component parent, Color themeColor) {
        super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null, 
              "遥控操作", true);
    this.THEME_COLOR = themeColor;
    // 使用统一对话框尺寸
    initializeDialog(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT);
        initializeRemoteContent();
        if (parent == null) {
            setLocationRelativeTo(null); // 居中显示
        }
    }
    
    private void initializeDialog(int width, int height) {
        setSize(width, height);
        setLocationRelativeTo(getParent());
        setResizable(false);
        getContentPane().setBackground(Color.WHITE);
    }
    
    private void initializeRemoteContent() {
        JPanel contentPanel = new JPanel(new BorderLayout());
        contentPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        JPanel directionPanel = new JPanel(new GridLayout(3, 3, 10, 10));
        directionPanel.setBackground(Color.WHITE);
        
        directionPanel.add(new JLabel());
        JButton upBtn = createDirectionButton("⬆️");
        directionPanel.add(upBtn);
        directionPanel.add(new JLabel());
        
        JButton leftBtn = createDirectionButton("⬅️");
        directionPanel.add(leftBtn);
        JButton centerBtn = createDirectionButton("⏺️");
        directionPanel.add(centerBtn);
        JButton rightBtn = createDirectionButton("➡️");
        directionPanel.add(rightBtn);
        
        directionPanel.add(new JLabel());
        JButton downBtn = createDirectionButton("⬇️");
        directionPanel.add(downBtn);
        directionPanel.add(new JLabel());
        
        JPanel speedPanel = new JPanel(new GridLayout(1, 2, 10, 0));
        speedPanel.setBackground(Color.WHITE);
        
        JButton backwardBtn = createSpeedButton("后退", new Color(255, 107, 107));
        JButton forwardBtn = createSpeedButton("前进", THEME_COLOR);
        
        speedPanel.add(backwardBtn);
        speedPanel.add(forwardBtn);
        
        contentPanel.add(directionPanel, BorderLayout.CENTER);
        contentPanel.add(speedPanel, BorderLayout.SOUTH);
        
        getContentPane().add(contentPanel);
    }
    
    private JButton createDirectionButton(String icon) {
        JButton button = new JButton(icon);
        button.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 20));
        button.setPreferredSize(new Dimension(60, 60));
        button.setBackground(Color.WHITE);
        button.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(new Color(200, 200, 200)),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)
        ));
        button.setFocusPainted(false);
        
        button.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                button.setBackground(new Color(240, 240, 240));
            }
            public void mouseReleased(MouseEvent e) {
                button.setBackground(Color.WHITE);
            }
        });
        
        return button;
    }
    
    private JButton createSpeedButton(String text, Color color) {
        JButton button = new JButton(text);
        button.setFont(new Font("微软雅黑", Font.BOLD, 14));
        button.setBackground(color);
        button.setForeground(Color.WHITE);
        button.setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0));
        button.setFocusPainted(false);
        
        button.addMouseListener(new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
                button.setBackground(color.darker());
            }
            public void mouseExited(MouseEvent e) {
                button.setBackground(color);
            }
        });
        
        return button;
    }
}