class DumpTableChooser extends JFileChooser {
private MainFrame mainFrame;
private Database db;
public DumpTableChooser(MainFrame mainFrame, Database db) {
this.mainFrame = mainFrame;
this.db = db;
this.setFileSelectionMode(DIRECTORIES_ONLY);
}
public void approveSelection() {
File file = this.getSelectedFile();
if (file.isDirectory()) {
//用戶選擇了目錄
File targetFile = new File(file.getAbsolutePath() + File.separator + //File.separator =\
this.db.getDatabaseName() + ".xls");//getAbsolutePath():返回抽象路徑名的絕對路徑名字符串
this.mainFrame.executeDumpTable(targetFile, this.db);
} else {
this.mainFrame.executeDumpTable(file, this.db);
}
super.approveSelection();
}
}
看不出來,核心代碼在executeDumpTable裡面