Add ActionListener for QuitMenuItem
This commit is contained in:
1 parent
892d7e6ff3
commit
d8acf6ebe8
2 files changed
+43
-2
No files matched your search
@@ -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