I want to use the JFileChooser to create a dialog box to save my 2 by 2 Array as a serialized object.
This is the code I have used previously to serialize objects and it works fine however, this just generates the file and puts it in the same directory as the program. I want to use the JFileChooser to choose the location of the saved file.
private void serializeMap() throws IOException {
File file = new File("map.txt");
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(grid);
oos.close();
}
So far this is all I have.
private void exportMap() {
KeyboardFocusManager.setCurrentKeyboardFocusManager(new DefaultKeyboardFocusManager());
JFileChooser fileChooser = new JFileChooser();
fileChooser.setSelectedFile(new File("map.txt"));
fileChooser.showSaveDialog(this);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(gameKeys);
}