Skip to content

Commit

Permalink
Tidied up save/load app state code (#115).
Browse files Browse the repository at this point in the history
  • Loading branch information
gbmhunter committed Apr 24, 2016
1 parent a7ef063 commit a0727b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
26 changes: 12 additions & 14 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ public void start(Stage primaryStage) throws Exception{

primaryStage.setMaximized(true);

//====== SAVING/LOADING APP STATE =====//

// Install event handler for when the app is closed
primaryStage.setOnCloseRequest((windowEvent) -> {
this.saveCalculatorState();
//this.saveCalculatorState();
}
);

// Load saved calculator state (if any)
loadCalculatorState();
//loadCalculatorState();

// Show the NinjaCalc app
primaryStage.show();
Expand All @@ -131,19 +133,18 @@ private void saveCalculatorState() {

try {
// Write to disk with FileOutputStream
FileOutputStream f_out = new
FileOutputStream fileOS = new
FileOutputStream(appStateFileName);

// Write object with ObjectOutputStream
ObjectOutputStream obj_out = new
ObjectOutputStream(f_out);
ObjectOutputStream objOS = new
ObjectOutputStream(fileOS);

// Write object out to disk
obj_out.writeObject(controller.getOpenCalculators());

obj_out.close();
objOS.writeObject(controller.getOpenCalculators());

f_out.close();
objOS.close();
fileOS.close();
} catch (FileNotFoundException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("FileNotFoundException");
Expand Down

0 comments on commit a0727b4

Please sign in to comment.