我正在使用接受來自用戶的值並將其存儲在變量(filePath)中的JFrame。我想在另一個類中使用這個值。我如何從JFrame中保存值並在另一個類中使用它?如何使用另一個類中的JFrame的值
的JFrame代碼:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Specify a file to save");
int userSelection = fileChooser.showSaveDialog(this);
if (userSelection == JFileChooser.APPROVE_OPTION) {
File fileToSave = fileChooser.getSelectedFile();
String filePath = fileToSave.getAbsolutePath();
}
類代碼:
String filename="";
我想要得到的文件路徑值轉換成文件名的字符串。
任何幫助?
爲什麼不簡單地將價值傳遞給需要它的其他類? – MadProgrammer
如何將價值傳遞給課堂?這是我的問題 –
聽起來好像這個框架應該是一個選項窗格或模態對話框。請參閱[使用多個JFrames,良好/錯誤的實踐?](http://stackoverflow.com/q/9554636/418556)爲了更快地獲得更好的幫助,請發佈[MCVE]或[Short,Self Contained,Correct Example]( http://www.sscce.org/)。 –