Merge Menubar features into mvc #17

Manually merged
regar42 merged 4 commits from menuBar into mvc 2017-12-16 17:03:56 +00:00
2 changed files with 43 additions and 2 deletions
Showing only changes of commit d8acf6ebe8 - Show all commits

No files matched your search

+9
View File
@@ -5,6 +5,7 @@ import maze.Maze;
public class MazeAppModel { public class MazeAppModel {
private Maze maze = new Maze("data/labyrinthe.txt"); private Maze maze = new Maze("data/labyrinthe.txt");
private boolean modified = false;
public void setMaze(Maze maze) { public void setMaze(Maze maze) {
this.maze = maze; this.maze = maze;
@@ -13,4 +14,12 @@ public class MazeAppModel {
public Maze getMaze() { public Maze getMaze() {
return maze; return maze;
} }
public boolean isModified() {
return modified;
}
public void saveToFile() {
maze.saveToTextFile("data/labyOutput.txt");
}
} }
+34 -2
View File
@@ -1,8 +1,15 @@
package ui; package ui;
import javax.swing.JMenuItem; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class QuitMenuItem extends JMenuItem { import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import model.MazeAppModel;
public class QuitMenuItem extends JMenuItem
implements ActionListener {
private final MazeApp mazeApp; private final MazeApp mazeApp;
@@ -10,6 +17,31 @@ public class QuitMenuItem extends JMenuItem {
super("Quit"); super("Quit");
this.mazeApp = mazeApp; this.mazeApp = mazeApp;
addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
MazeAppModel mazeAppModel = mazeApp.getMazeAppModel();
if (mazeAppModel.isModified()) {
int response = JOptionPane.showInternalOptionDialog(this,
"Maze not saved. Save it ?",
"Quit application",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null,null,null) ;
switch (response) {
case JOptionPane.CANCEL_OPTION:
return;
case JOptionPane.OK_OPTION:
mazeAppModel.saveToFile();
break;
case JOptionPane.NO_OPTION:
break;
}
}
System.exit(0) ;
} }
} }