单机工具--jframe应用

原创 2016年06月01日 11:35:20

最近看同事写的一个工具很有意思,分享下

public class EncodingPanel extends JPanel {
private static final long serialVersionUID = 1L;


public EncodingPanel() {
super(new GridBagLayout());
initComponent();
}
public static void main(String[] args) {
new EncodingPanel().initComponent();
}


/**
* 初始化控件
*/
private void initComponent() {
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.ipady = 8;
constraints.insets = new Insets(8, 0, 0, 0);
// 输入:
JLabel srcFileLabel = new JLabel("输入:");
constraints.gridwidth = 1;
constraints.weightx = 0;
this.add(srcFileLabel, constraints);
final JComboBox<String> srcEncodeType = new JComboBox<String>(
new String[] { "GBK", "GB2312", "UTF-8", "ISO8859-1" });
constraints.gridwidth = 2;
constraints.weightx = 0;
this.add(srcEncodeType, constraints);
final JButton srcButton = new JButton("请选择输入文件路径");
constraints.gridwidth = 3;
constraints.weightx = 1;
this.add(srcButton, constraints);
srcButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String file = DocParseFrame.chooseFile(JFileChooser.FILES_AND_DIRECTORIES);
if (!file.equals("")) {
srcButton.setText(file);
}
}
});
// 输出:
JLabel targetFileLabel = new JLabel("输出:");
constraints.gridwidth = 1;
constraints.gridy = 1;
constraints.weightx = 0;
this.add(targetFileLabel, constraints);
final JComboBox<String> targetEncodeType = new JComboBox<String>(
new String[] { "GBK", "GB2312", "UTF-8", "ISO8859-1" });
constraints.gridwidth = 2;
constraints.weightx = 0;
constraints.gridy = 1;
this.add(targetEncodeType, constraints);
final JButton targetButton = new JButton("请选择输出文件路径");
constraints.gridwidth = 3;
constraints.gridy = 1;
constraints.weightx = 0;
this.add(targetButton, constraints);
targetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String file = DocParseFrame.chooseFile(JFileChooser.FILES_AND_DIRECTORIES);
if (!file.equals("")) {
targetButton.setText(file);
}
}
});
// 编码选择


// 转换按钮
final JButton changeButton = new JButton("转换");
constraints.gridwidth = 2;
constraints.gridy = 2;
constraints.weightx = 0;
constraints.insets = new Insets(24, 10, 0, 0);
this.add(changeButton, constraints);
final JLabel progresslabel = new JLabel("");
constraints.gridwidth = 2;
constraints.gridy = 2;
constraints.weightx = 0;
this.add(progresslabel, constraints);


// 错误面板
final JTextArea errTextArea = new JTextArea();
constraints.gridwidth = 6;
constraints.gridy = 3;
constraints.weighty = 20;


constraints.insets = new Insets(10, 0, 10, 0);
this.add(errTextArea, constraints);


changeButton.addActionListener(new ActionListener() {


@Override
public void actionPerformed(ActionEvent e) {
final String inFilePath = srcButton.getText();
final String inCharsetName = srcEncodeType.getSelectedItem().toString();
final String outFilePath = targetButton.getText();
final String outCharsetName = targetEncodeType.getSelectedItem().toString();
if (inFilePath.equals("请选择输入文件路径") || outFilePath.equals("请选择输出文件路径")) {
JOptionPane.showMessageDialog(EncodingPanel.this, "输入参数不正确");
return;
}
changeButton.setEnabled(false);
new Thread() {
public void run() {
try {
new EncodingUtil().recursionFileEncodingTrans(inFilePath, inCharsetName, outFilePath,
outCharsetName, new EncodingUtil.ProgressInterface() {
@Override
public void progress(int index) {
progresslabel.setText("正在处理:第" + index + "个");
}
});
progresslabel.setText("转换完毕");
} catch (Exception e) {
e.printStackTrace();
errTextArea.setText(e.toString());
}finally{
changeButton.setEnabled(true);
}
};
}.start();
}
});
}


}

package com.dinfo.oec.doc.ui;


import java.io.File;


import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;


public class DocParseFrame extends JFrame {
private static final long serialVersionUID = 1L;


public DocParseFrame() {
createJTabbedPane();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 400, 400);
this.setVisible(true);
}


public void createJTabbedPane() {
JTabbedPane tabbedPane = new JTabbedPane();
// 1。编码转换
tabbedPane.addTab("编码转换", new EncodingPanel());
// 2.文档解析
tabbedPane.addTab("文档解析", new DocParsePanel());
getContentPane().add(tabbedPane);
}


// 选择文件
public static String chooseFile(int chooseType) {
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(chooseType);
jfc.showDialog(new JLabel(), "选择");
File file = jfc.getSelectedFile();
if (file != null) {
return file.getAbsolutePath();
} else {
return "";
}
}


public static void main(String[] args) {
new DocParseFrame();
}


}

很有意思的东东

版权声明:

相关文章推荐

java+JFrame框架的应用

  • 2010-11-30 10:52
  • 59KB
  • 下载

Java GUI:基于JFrame、带有事件处理的窗口型应用程序

本文使用包javax.swing中的JFrame来创建自己的窗口类型,该窗口将放在GUI部件中,用户可以使用GUI部件交互地驱动程序。这个程序还引用了类StringTokenizer(包java.ut...

Text Line Dereplication BigData Tool 文本行去重化 大数据工具 130Gb 20亿行数据 60分钟即可完成去重操作 最快的单机版软件

Text Line Dereplication BigData Tool 文本行去重化 大数据工具 本软件特点及其描述: 1.平均处理速度60Mb/s(读写速度),例如130Gb的txt文件,大约60...

java JFrame框架的应用

  • 2010-06-21 17:06
  • 59KB
  • 下载

JFrame 代码自动生成工具

  • 2011-03-30 08:56
  • 960KB
  • 下载

[13] DevOps 自动化运维工具Chef----用chef-apply命令单机运行Chef配方(Receipt)

前面的12篇文章唠唠叨叨了如何安装Chef,如何查看Chef的数据库的密码,就是没有分享如何跑一个简单的Chef的配方去完成一项任务。这篇文章的目的就是让大家见识一下如何用Chef执行一个简单的任务。...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)