package zhuye; import ui.UIConfig; import javax.swing.*; import publicway.buttonset; import java.awt.*; import java.awt.event.*; public class AreaSelectionDialog extends JDialog { private final Color THEME_COLOR; private final JLabel areaNameLabel; private final JLabel statusLabel; public AreaSelectionDialog(Component parent, Color themeColor, JLabel areaNameLabel, JLabel statusLabel) { super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null, "选择地块", true); this.THEME_COLOR = themeColor; this.areaNameLabel = areaNameLabel; this.statusLabel = statusLabel; // 统一对话框尺寸 initializeDialog(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT); initializeAreaContent(); 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 initializeAreaContent() { JPanel contentPanel = new JPanel(); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); contentPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); String[][] areaOptions = { {"🏡", "前院草坪"}, {"🌳", "后院草坪"}, {"🌷", "花园区域"} }; for (String[] area : areaOptions) { JButton areaBtn = createAreaButton(area[0], area[1]); contentPanel.add(areaBtn); contentPanel.add(Box.createRigidArea(new Dimension(0, 10))); } JButton addAreaBtn = buttonset.createStyledButton("➕ 新增地块", THEME_COLOR); addAreaBtn.setFont(new Font("微软雅黑", Font.BOLD, 14)); addAreaBtn.setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0)); addAreaBtn.setAlignmentX(Component.CENTER_ALIGNMENT); addAreaBtn.addActionListener(e -> { JOptionPane.showMessageDialog(this, "打开新增地块功能"); }); contentPanel.add(Box.createVerticalGlue()); contentPanel.add(addAreaBtn); getContentPane().add(contentPanel); } private JButton createAreaButton(String icon, String text) { JButton button = buttonset.createStyledButton("