Add UI to the project #29
No files matched your search
@@ -5,6 +5,7 @@ import maze.Maze;
|
||||
public class MazeAppModel {
|
||||
|
||||
private Maze maze = new Maze("data/labyrinthe.txt");
|
||||
private boolean modified = false;
|
||||
|
||||
public void setMaze(Maze maze) {
|
||||
this.maze = maze;
|
||||
@@ -13,4 +14,12 @@ public class MazeAppModel {
|
||||
public Maze getMaze() {
|
||||
return maze;
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void saveToFile() {
|
||||
maze.saveToTextFile("data/labyOutput.txt");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
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;
|
||||
|
||||
@@ -10,6 +17,31 @@ public class QuitMenuItem extends JMenuItem {
|
||||
|
||||
super("Quit");
|
||||
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) ;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user