代码拉取完成,页面将自动刷新
package com.ui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.utils.FileOperation;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.awt.event.ActionEvent;
public class MainDailog extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTextField filePath_text;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
MainDailog dialog = new MainDailog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
dialog.setTitle("格式转换");
dialog.setResizable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
private String getSelectFilePath() {
// TODO Auto-generated method stub
JFileChooser jfc=new JFileChooser();
FileNameExtensionFilter filter =
new FileNameExtensionFilter(
"xmind", "xmind");
jfc.setFileFilter(filter);
jfc.showDialog(new JLabel(), "选择");
File file=jfc.getSelectedFile();
if(file != null){
return jfc.getSelectedFile().getAbsolutePath();
}else{
return null;
}
}
private String getSaveFilePath(){
JFileChooser jf = new JFileChooser();
jf.setFileSelectionMode(JFileChooser.SAVE_DIALOG | JFileChooser.DIRECTORIES_ONLY);
jf.showDialog(new JLabel(), "保存");
File fi = jf.getSelectedFile();
String f = fi.getAbsolutePath() + ".xlsx";
if(fi != null && fi.getName() != null && !fi.getName().equals("") && fi.getAbsolutePath() != null &&
!fi.getAbsolutePath().equals("")){
return f;
}else{
return null;
}
}
/**
* Create the dialog.
*/
public MainDailog() {
setBounds(100, 100, 610, 236);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JButton okButton = new JButton("\u8F6C\u6362");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(filePath_text.getText().equals("") || filePath_text.getText()==null){
JOptionPane.showConfirmDialog (null, "目录不得为空", "提示", JOptionPane.YES_OPTION);
}else{
File file = new File(filePath_text.getText());
if(!file.exists()){
JOptionPane.showConfirmDialog (null, "该文件不存在", "提示", JOptionPane.YES_OPTION);
}else{
FileOperation fo = new FileOperation();
String outPath = getSaveFilePath();
if(outPath == null){
JOptionPane.showConfirmDialog (null, "保存文件的路径不对", "提示", JOptionPane.YES_OPTION);
}else{
fo.unZipFiles(filePath_text.getText());
if(fo.analysisXML(new File(filePath_text.getText()).getParent()+ "\\tm\\content.xml")){
if(fo.writeExcel(outPath)){
JOptionPane.showConfirmDialog (null, "转换成功!", "提示", JOptionPane.YES_OPTION);
try {
Runtime.getRuntime().exec("explorer.exe " + new File(outPath).getParent());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else{
JOptionPane.showConfirmDialog (null, "转换失败!", "提示", JOptionPane.YES_OPTION);
}
fo.cleanTemp(new File(new File(filePath_text.getText()).getParent() + "\\tm"));
}else{
JOptionPane.showConfirmDialog (null, "非法的xmind文件!没有得到解压的xml文件", "转换失败!", JOptionPane.YES_OPTION);
}
}
}
}
}
});
okButton.setBounds(230, 126, 141, 36);
contentPanel.add(okButton);
okButton.setActionCommand("OK");
getRootPane().setDefaultButton(okButton);
}
filePath_text = new JTextField();
filePath_text.setBounds(54, 66, 390, 28);
contentPanel.add(filePath_text);
filePath_text.setColumns(10);
JButton select_btn = new JButton("\u9009\u62e9\u6587\u4ef6");
select_btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String path = getSelectFilePath();
filePath_text.setText(path);
}
});
select_btn.setBounds(454, 61, 115, 36);
contentPanel.add(select_btn);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。