From 390fc7375aecc1a0e58d52f38f2adc16f1971858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Thu, 16 Oct 2025 01:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=8F=9C=E5=8D=95=E6=A0=8F?= =?UTF-8?q?=EF=BC=8C=E4=BB=85=E4=BF=9D=E7=95=99=E5=B7=A5=E5=85=B7=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/example/ImageDotMarker.java | 92 +++++++++++-------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/example/ImageDotMarker.java b/src/main/java/org/example/ImageDotMarker.java index ae403d3..69c3053 100644 --- a/src/main/java/org/example/ImageDotMarker.java +++ b/src/main/java/org/example/ImageDotMarker.java @@ -35,10 +35,7 @@ public class ImageDotMarker extends JFrame { // 设置窗口在屏幕中心显示 setLocationRelativeTo(null); - // 创建菜单栏 - createMenuBar(); - - // 创建工具栏 + // 只保留工具栏 createToolbar(); // 创建主面板 @@ -48,36 +45,7 @@ public class ImageDotMarker extends JFrame { createStatusBar(); } - private void createMenuBar() { - JMenuBar menuBar = new JMenuBar(); - JMenu fileMenu = new JMenu("文件"); - JMenuItem openItem = new JMenuItem("打开图片"); - JMenuItem saveItem = new JMenuItem("保存图片"); - JMenuItem exitItem = new JMenuItem("退出"); - openItem.addActionListener(e -> openImage()); - saveItem.addActionListener(e -> saveImage()); - exitItem.addActionListener(e -> System.exit(0)); - - fileMenu.add(openItem); - fileMenu.add(saveItem); - fileMenu.addSeparator(); - fileMenu.add(exitItem); - menuBar.add(fileMenu); - - JMenu pointMenu = new JMenu("标记点"); - JMenuItem clearItem = new JMenuItem("清除所有标记"); - JMenuItem exportTextItem = new JMenuItem("导出坐标(文本)"); - - clearItem.addActionListener(e -> clearPoints()); - exportTextItem.addActionListener(e -> exportPointsAsText()); - - pointMenu.add(clearItem); - pointMenu.add(exportTextItem); - menuBar.add(pointMenu); - - setJMenuBar(menuBar); - } private void createToolbar() { JToolBar toolBar = new JToolBar(); @@ -96,9 +64,18 @@ public class ImageDotMarker extends JFrame { clearBtn.addActionListener(e -> clearPoints()); JButton exportTextBtn = new JButton("导出文本"); - exportTextBtn.setToolTipText("导出坐标为文本"); + exportTextBtn.setToolTipText("导出坐标为CSV文件"); exportTextBtn.addActionListener(e -> exportPointsAsText()); + toolBar.add(openBtn); + toolBar.add(saveBtn); + toolBar.addSeparator(); + toolBar.add(clearBtn); + toolBar.add(exportTextBtn); + + // 添加分隔符 + toolBar.addSeparator(); + // 缩放控件 JButton zoomInBtn = new JButton("放大"); zoomInBtn.addActionListener(e -> zoomImage(1.25)); @@ -109,15 +86,30 @@ public class ImageDotMarker extends JFrame { JButton resetZoomBtn = new JButton("重置"); resetZoomBtn.addActionListener(e -> resetZoom()); - toolBar.add(openBtn); - toolBar.add(saveBtn); - toolBar.addSeparator(); - toolBar.add(clearBtn); - toolBar.add(exportTextBtn); - toolBar.addSeparator(); toolBar.add(zoomInBtn); toolBar.add(zoomOutBtn); toolBar.add(resetZoomBtn); + + // 添加分隔符 + toolBar.addSeparator(); + + // 添加帮助和退出按钮 + JButton helpBtn = new JButton("帮助"); + helpBtn.setToolTipText("使用说明"); + helpBtn.addActionListener(e -> showHelpDialog()); + + JButton aboutBtn = new JButton("关于"); + aboutBtn.setToolTipText("关于软件"); + aboutBtn.addActionListener(e -> showAboutDialog()); + + JButton exitBtn = new JButton("退出"); + exitBtn.setToolTipText("退出程序"); + exitBtn.addActionListener(e -> System.exit(0)); + + toolBar.add(helpBtn); + toolBar.add(aboutBtn); + toolBar.addSeparator(); + toolBar.add(exitBtn); add(toolBar, BorderLayout.NORTH); } @@ -250,6 +242,26 @@ public class ImageDotMarker extends JFrame { JLabel statusLabel = (JLabel) statusPanel.getComponent(0); statusLabel.setText(message); } + + private void showAboutDialog() { + JOptionPane.showMessageDialog(this, + "图片标点工具\n" + + "版本 1.0\n" + + "用于在图片上标记点并导出坐标数据", + "关于", JOptionPane.INFORMATION_MESSAGE); + } + + private void showHelpDialog() { + JOptionPane.showMessageDialog(this, + "使用说明:\n\n" + + "1. 点击'打开'按钮选择要标记的图片\n" + + "2. 在图片上点击添加标记点\n" + + "3. 双击标记点可编辑名称\n" + + "4. 使用缩放按钮调整图片显示大小\n" + + "5. 在右侧面板管理标记点(删除、调整顺序)\n" + + "6. 点击'导出文本'将标记点坐标导出为CSV文件", + "使用说明", JOptionPane.INFORMATION_MESSAGE); + } private void openImage() { JFileChooser fileChooser = new JFileChooser();