主要目的是通过一个选择程序的对话框来选择一个文件的路径,然后把这个路径传到后台去(只传路径,不用考虑打开文件的问题).现在当选择完路径后,路径被自动传到了后台,可是我想要同时自动关闭掉那个JFrame但不关闭整个程序(因为有后台的处理),请问关闭代码应该怎么写,写在什么地方??代码如下:
package ft;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class MyTest extends JFrame implements ActionListener{
JButton jbtn = null;
JTextField jtf = null;
public MyTest(){
this.setLayout(new FlowLayout());
jbtn = new JButton("打开..");
jbtn.addActionListener(this);
jtf = new JTextField(30);
this.add(jtf);
this.add(jbtn);
this.setSize(400,400);
this.setVisible(true);
this.pack();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(jbtn)){
FileDialog fd = new FileDialog(this);
fd.setVisible(true);
String a = fd.getDirectory()+fd.getFile();
System.out.println(a);
//System.exit(0);
}
}
public static void main(String[] args){
new MyTest();
}
}