From 5242c66f7c2d00563e5d4d3c8eebe965c3944a39 Mon Sep 17 00:00:00 2001 From: zhanghai <120228220@qq.com> Date: Fri, 8 Dec 2023 13:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BD=AF=E4=BB=B6=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/docus/sw/fenpan/MyApplication.java | 67 ++++++++++--------- .../com/docus/sw/souyin/CheckService.java | 6 +- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/docus/sw/fenpan/MyApplication.java b/src/main/java/com/docus/sw/fenpan/MyApplication.java index ddcd214..6b01283 100644 --- a/src/main/java/com/docus/sw/fenpan/MyApplication.java +++ b/src/main/java/com/docus/sw/fenpan/MyApplication.java @@ -357,6 +357,23 @@ public class MyApplication { leftGbc.gridx = 2; leftPanel.add(fileChooserButton, leftGbc); + + + + leftGbc.gridx = 0; + leftGbc.gridy = 1; + leftGbc.anchor = GridBagConstraints.WEST; + leftPanel.add(new JLabel("保存路径选择:"), leftGbc); + JTextField savefilePathField = new JTextField(20); + leftGbc.gridx = 1; + leftGbc.gridwidth = 1; + leftPanel.add(savefilePathField, leftGbc); + + JButton fileChooserButton2 = new JButton("选择目录"); + leftGbc.gridx = 2; + leftPanel.add(fileChooserButton2, leftGbc); + + // 文件选择按钮的动作监听器,打开文件选择对话框 fileChooserButton.addActionListener(new ActionListener() { @Override @@ -371,38 +388,22 @@ public class MyApplication { } }); -// leftGbc.gridx = 0; -// leftGbc.gridy = 1; -// leftGbc.anchor = GridBagConstraints.WEST; -// leftPanel.add(new JLabel("dpi:"), leftGbc); -// JTextField dpiField = new JTextField(20); -// leftGbc.gridx = 1; -// leftPanel.add(dpiField, leftGbc); -// -// leftGbc.gridx = 0; -// leftGbc.gridy = 2; -// leftPanel.add(new JLabel("胶片长度:"), leftGbc); -// JTextField filmLengthField = new JTextField(20); -// leftGbc.gridx = 1; -// leftPanel.add(filmLengthField, leftGbc); -// -// leftGbc.gridx = 0; -// leftGbc.gridy = 3; -// leftPanel.add(new JLabel("图像格式:"), leftGbc); -// String[] imageFormats = {"图片", "pdf", "word"}; -// JComboBox formatComboBox = new JComboBox<>(imageFormats); -// leftGbc.gridx = 1; -// leftPanel.add(formatComboBox, leftGbc); -// -// // 添加图像格式选择框的监听器,可以根据选择的格式执行相应操作 -// formatComboBox.addActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent e) { -// String selectedFormat = (String) formatComboBox.getSelectedItem(); -// // 在这里执行根据选择的格式的操作 -// System.out.println("选择的图像格式: " + selectedFormat); -// } -// }); + + + // 文件选择按钮的动作监听器,打开文件选择对话框 + fileChooserButton2.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnValue = fileChooser.showOpenDialog(null); + if (returnValue == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + savefilePathField.setText(selectedFile.getAbsolutePath()); + } + } + }); + leftGbc.gridx = 1; @@ -440,7 +441,7 @@ public class MyApplication { // 模拟耗时操作 try { - new CheckService().index(filePathField.getText()); + new CheckService().index(filePathField.getText(),savefilePathField.getText()); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/src/main/java/com/docus/sw/souyin/CheckService.java b/src/main/java/com/docus/sw/souyin/CheckService.java index 3b8bfc4..f8536fc 100644 --- a/src/main/java/com/docus/sw/souyin/CheckService.java +++ b/src/main/java/com/docus/sw/souyin/CheckService.java @@ -35,10 +35,10 @@ public class CheckService { public static void main(String[] args) throws IOException { Config.loadConfig(); String path = "C:\\Users\\zhanghai\\Desktop\\桌面\\test\\ppp\\ppp"; - new CheckService().index(path); +// new CheckService().index(path); } - public void index(String path) throws IOException { + public void index(String path,String savepath) throws IOException { Map map = new HashMap<>(); findAllDir(path, map); @@ -166,7 +166,7 @@ public class CheckService { } } - EasyExcel.write("check" + ".xls", CheckPageRow.class).sheet("test").doWrite(checkPageRows); + EasyExcel.write(savepath+"/check" + ".xls", CheckPageRow.class).sheet("test").doWrite(checkPageRows); }