private String open() { try { FileContents fc = fos.openFileDialog(null, null); return readFromFile(fc); } catch (IOException ioe) { ioe.printStackTrace(System.out); return null; } }
public static String getLoadFileName(Frame frame) { if (applet != null) { showAppletWarning(frame); return null; } String extension = RiskFileFilter.RISK_SAVE_FILES; if (webstart != null) { try { javax.jnlp.FileOpenService fos = (javax.jnlp.FileOpenService) javax.jnlp.ServiceManager.lookup("javax.jnlp.FileOpenService"); javax.jnlp.FileContents fc = fos.openFileDialog(SAVES_DIR, new String[] {extension}); if (fc != null) { fileio.put(fc.getName(), fc); return fc.getName(); } else { return null; } } catch (Exception e) { return null; } } else { File dir = getSaveGameDir(); JFileChooser fc = new JFileChooser(dir); fc.setFileFilter(new RiskFileFilter(extension)); int returnVal = fc.showDialog( frame, TranslationBundle.getBundle().getString("mainmenu.loadgame.loadbutton")); if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) { java.io.File file = fc.getSelectedFile(); // Write your code here what to do with selected file return file.getAbsolutePath(); } else { // Write your code here what to do if user has canceled Open dialog return null; } } }