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;
|
}
|
}
|