import javax.swing.JFileChooser;
/*
import weka.core.converters.ConverterUtils.DataSource;
import weka.core.converters.XRFFSaver;
import weka.core.Instances;
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/*
* mainFrm.java
*
* Created on 2007年8月13日, 下午8:43
*/
/**
*
* @author Peng
*/
public class mainFrm extends javax.swing.JFrame {
JFileChooser fileChooser = null;
/** Creates new form mainFrm */
public mainFrm() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {
lblArffFile = new javax.swing.JLabel();
lblTxtFile = new javax.swing.JLabel();
txtFieldArff = new javax.swing.JTextField();
txtFieldTXT = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
txtFieldXRFF = new javax.swing.JTextField();
btnConvert = new javax.swing.JButton();
btnArffChooser = new javax.swing.JButton();
btnTXTChooser = new javax.swing.JButton();
btnSaveXRFF = new javax.swing.JButton();
lblStatus = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("XRFF=ARFF+TXT");
lblArffFile.setText("ARFF File: ");
lblTxtFile.setText("TXT File: ");
jLabel1.setText("XRFF File: ");
btnConvert.setText("Convert");
btnConvert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnConvertActionPerformed(evt);
}
});
btnArffChooser.setText("Browse");
btnArffChooser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnArffChooserActionPerformed(evt);
}
});
btnTXTChooser.setText("Browse");
btnTXTChooser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTXTChooserActionPerformed(evt);
}
});
btnSaveXRFF.setText("Save to");
btnSaveXRFF.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSaveXRFFActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(lblArffFile)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtFieldArff, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lblTxtFile)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtFieldTXT))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtFieldXRFF))))
.addGroup(layout.createSequentialGroup()
.addGap(116, 116, 116)
.addComponent(btnConvert, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnTXTChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnArffChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSaveXRFF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblArffFile)
.addComponent(txtFieldArff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnArffChooser))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblTxtFile)
.addComponent(btnTXTChooser)
.addComponent(txtFieldTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(btnSaveXRFF)
.addComponent(txtFieldXRFF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnConvert)
.addComponent(lblStatus))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnConvertActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
/*
try{
// load data
DataSource source = new DataSource(txtFieldArff.getText());
Instances data = source.getDataSet();
if (data.classIndex() == -1)
data.setClassIndex(data.numAttributes() - 1);
// read and set weights
BufferedReader reader = new BufferedReader(new FileReader(txtFieldTXT.getText()));
for (int i = 0; i < data.numInstances(); i++) {
String line = reader.readLine();
double weight = Double.parseDouble(line);
data.instance(i).setWeight(weight);
}
reader.close();
// save data
XRFFSaver saver = new XRFFSaver();
saver.setFile(new File(txtFieldXRFF.getText()));
saver.setInstances(data);
saver.writeBatch();
lblStatus.setText("Done");
}catch(Exception e){
e.printStackTrace();
lblStatus.setText("Error");
}
*/
}
private void btnSaveXRFFActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
fileChooser = new JFileChooser();
//int arffOpt = arffChooser.showOpenDialog(this);
fileChooser.showSaveDialog(this);
txtFieldXRFF.setText(fileChooser.getSelectedFile().getPath());
}
private void btnTXTChooserActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
fileChooser = new JFileChooser();
//int arffOpt = arffChooser.showOpenDialog(this);
fileChooser.showOpenDialog(this);
txtFieldTXT.setText(fileChooser.getSelectedFile().getPath());
}
private void btnArffChooserActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
fileChooser = new JFileChooser();
//int arffOpt = arffChooser.showOpenDialog(this);
fileChooser.showOpenDialog(this);
txtFieldArff.setText(fileChooser.getSelectedFile().getPath());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mainFrm().setVisible(true);
}
});
}
// 变量声明 - 不进行修改
private javax.swing.JButton btnArffChooser;
private javax.swing.JButton btnConvert;
private javax.swing.JButton btnSaveXRFF;
private javax.swing.JButton btnTXTChooser;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel lblArffFile;
private javax.swing.JLabel lblStatus;
private javax.swing.JLabel lblTxtFile;
private javax.swing.JTextField txtFieldArff;
private javax.swing.JTextField txtFieldTXT;
private javax.swing.JTextField txtFieldXRFF;
// 变量声明结束
}
如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/
2007年8月13日星期一
Java File Chooser Simple Application
订阅:
博文评论 (Atom)
没有评论:
发表评论