package csu.com.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import csu.com.biz.Measure;
import csu.com.biz.Operation;
import csu.com.data.FinalData;
import javax.swing.JLabel;
public class OpenFrame extends JFrame implements ActionListener{
JFrame of;
JPanel pnlMain;
JTextField txtfile;
JButton btnSelect;
JFileChooser fc = new JFileChooser();
private JTextField textField;
main m;
private JLabel label_2;
private JTextField filename;
public OpenFrame( JFrame m ) {
this.setBounds(200, 200, 300, 400);
this.setVisible(true);
this.m = (main) m;
this.of = this;
init();
}
private void init() {
pnlMain=new JPanel();
this.getContentPane().add(pnlMain);
// 文件选择
txtfile=new JTextField(10);
txtfile.setText("\u8BF7\u9009\u62E9\u6587\u4EF6...");
txtfile.setBounds(24, 212, 144, 21);
btnSelect =new JButton("选择");
btnSelect.setBounds(186, 211, 72, 23);
btnSelect.addActionListener(this);
pnlMain.setLayout(null);
pnlMain.add(txtfile);
pnlMain.add(btnSelect);
JLabel label = new JLabel("\u85AA \u8D44");
label.setBounds(24, 116, 47, 30);
pnlMain.add(label);
textField = new JTextField();
textField.setBounds(81, 121, 110, 21);
pnlMain.add(textField);
textField.setColumns(10);
JLabel label_1 = new JLabel("\u5143/\u4EBA\u6708");
label_1.setBounds(212, 121, 46, 21);
pnlMain.add(label_1);
JButton button = new JButton("\u53D6\u6D88");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
setVisible(false);
}
});
button.setBounds(40, 310, 72, 23);
pnlMain.add(button);
JButton button_1 = new JButton("\u786E\u5B9A");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionForAdd(e);
}
});
button_1.setBounds(186, 310, 72, 23);
pnlMain.add(button_1);
label_2 = new JLabel("\u6A21\u5757\u540D");
label_2.setBounds(24, 56, 61, 21);
pnlMain.add(label_2);
filename = new JTextField();
filename.setBounds(78, 56, 180, 21);
pnlMain.add(filename);
filename.setColumns(10);
//添加这样一个类来过滤
class TxtFileFilter extends javax.swing.filechooser.FileFilter {
@Override
public boolean accept( File f ) {
if( f.isDirectory() || f.getName().endsWith( ".java" ) ) {
return true;
} else {
return false;
}
}
@Override
public String getDescription() {
// TODO Auto-generated method stub
return null;
}}
TxtFileFilter filter = new TxtFileFilter ();
fc.setFileFilter( filter );
// 设置薪资
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btnSelect){
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int intRetVal = fc.showOpenDialog(this);
if( intRetVal == JFileChooser.APPROVE_OPTION){
String filepath = fc.getSelectedFile().getPath();
txtfile.setText(filepath);
// ms.locMeasure(filepath);
}
}
}
////追加行时调用事件
public void actionForAdd(ActionEvent e) {
Object object = e.getSource();
// 获取数据
String name = this.filename.getText().trim();
String filepath = this.txtfile.getText().trim();
double pay = Double.parseDouble( this.textField.getText() );
Operation op = new Operation();
op.setData(name, filepath, pay);
Object[] obj = new Object[]{ FinalData.filename, FinalData.rule, FinalData.locf, FinalData.pay, FinalData.exp, FinalData.cost, FinalData.time };
m.model.addRow(obj);
setVisible(false);
}
public static void main(String[] args){
}
}