Files
TpMazeJava/src/ui/FileBox.java
T
regar42 dc8de8c707 Add MazeModelInterface and Maze exceptions
* Add an interface for MazeModel
* Add MazeReadingException and MazeSavingException to handle errors when
  reading/saving a maze from/to a file (see #4)
* Useless methods removal (shallowShortest)
* Add javadoc
2018-01-14 17:05:42 +01:00

33 lines
888 B
Java

package ui;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
public final class FileBox {
private static JFileChooser fileChooser = new JFileChooser();
private static FileNameExtensionFilter filter =
new FileNameExtensionFilter("Text files", "txt");
public static String load(MazeApp mazeApp) {
fileChooser.setFileFilter(filter);
int returnVal = fileChooser.showOpenDialog(mazeApp);
if(returnVal == JFileChooser.APPROVE_OPTION) {
String filename = fileChooser.getSelectedFile().getPath();
return filename;
}
return null;
}
public static String save(MazeApp mazeApp) {
fileChooser.setFileFilter(filter);
int returnVal = fileChooser.showSaveDialog(mazeApp);
if(returnVal == JFileChooser.APPROVE_OPTION) {
String filename = fileChooser.getSelectedFile().getPath();
return filename;
}
return null;
}
}