Java codeJButton jbfile=new JButton();
JTextField jtfile=new JTextField("",10);
jbfile.addActionListener(new ImportFrame_jbfile_actionAdapter(this));
public void jbfile_actionPerformed(ActionEvent e) {
//建立文件选择框对象
JFileChooser fc=new JFileChooser();
//设定文件选择框标题
fc.setDialogTitle("Open class File");
//显示文件选择框,在选择后将结果储存到returnVal变量中
int returnVal = fc.showOpenDialog(this.getComponent(0));
//如果用户选择了文件,并点击了"Opne/打开"按钮,显示用户选择的文件全名路径,
//如果用户点击"Close/关闭"按钮,以及其它方式退出文件选择框,则什么也不做。
if (returnVal == JFileChooser.APPROVE_OPTION){
File file = fc.getSelectedFile();
jtfile.setText(file.getPath());
}
}
class ImportFrame_jbfile_actionAdapter implements ActionListener {
private ImportFrame adaptee;
ImportFrame_jbfile_actionAdapter(ImportFrame
adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbfile_actionPerformed(e);
}
}