Fix access denied bug

master
John 2022-06-19 14:37:40 -07:00
parent cf134e3104
commit 45e3911815
2 changed files with 13 additions and 2 deletions

View File

@ -38,6 +38,7 @@ public class FileManager {
o = objectStream.readObject();
objectStream.close();
fileStream.close();
System.out.println("done");
return o;
}

View File

@ -5,6 +5,9 @@ Runs the constructor in GamePanel class
*/
import java.awt.*;
import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -25,16 +28,23 @@ public class GameFrame extends JFrame{
main = new CameraPanel();
main.setLayout(new CardLayout());
try {
System.out.println("done2");
game = (GamePanel)FileManager.readObjectFromFile("local/game_state.dat", Arrays.asList("Any"));
game.gameFrame = main;
game.isContinue = true;
game.addUserInterface();
game.startThread();
} catch (IOException | ClassNotFoundException | ClassCastException | SecurityException e) {
System.out.println(e);
game = new GamePanel(main); //run GamePanel constructor
game.startThread();
}
// delete saves to prevent unexpected behaviour
try {
Files.deleteIfExists(Path.of("local/game_state.dat"));
Files.deleteIfExists(Path.of("local/temp_state.dat"));
} catch (FileSystemException e) {
System.out.println(e);
}
game.startThread();
/*
try {
// read previously saved controls