Repository navigation
Expand file tree
/
Copy pathClosingHandler.java
More file actions
93 lines (83 loc) · 2.72 KB
/
Copy pathClosingHandler.java
File metadata and controls
93 lines (83 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package gui;
import log.Logger;
import sound.MusicPlayer;
import javax.swing.*;
import javax.swing.event.InternalFrameEvent;
import java.io.Serializable;
import java.util.ResourceBundle;
public class ClosingHandler implements Serializable {
public ClosingHandler(){
}
public enum ClosingType{
GAME, LOG, MUSIC, DISTANCE, COORDINATES
}
private enum Context{
EXIT, CLOSE
}
public void handleClosing(ResourceBundle bundle) {
int answer = showWarningMessage(bundle, Context.EXIT);
if (answer == JOptionPane.YES_OPTION) {
Logger.info("getQuit");
System.exit(0);
}
else{
Logger.info("getNotQuit");
}
}
public void handleClosing(JInternalFrame window, InternalFrameEvent e, ResourceBundle bundle, ClosingType type) {
int answer = showWarningMessage(bundle, Context.CLOSE);
String yesMessage = "";
String noMessage = "";
switch (type) {
case DISTANCE:
yesMessage = "closeDistanceWindow";
noMessage = "notCloseDistanceWindow";
break;
case COORDINATES:
yesMessage = "closeCoordinatesWindow";
noMessage = "notCloseCoordinatesWindow";
break;
case GAME:
yesMessage = "closeGameWindow";
noMessage = "notCloseGameWindow";
break;
case LOG:
yesMessage = "closeLogWindow";
noMessage = "notCloseLogWindow";
break;
case MUSIC:
yesMessage = "closeMusicWindow";
noMessage = "notCloseMusicWindow";
break;
}
if (answer == JOptionPane.YES_OPTION) {
Logger.info(yesMessage);
window.dispose();
}
else{
Logger.info(noMessage);
}
}
private int showWarningMessage(ResourceBundle bundle, Context context) {
String[] buttonLabels = new String[] {bundle.getString("accept"), bundle.getString("not accept")};
String defaultOption = buttonLabels[0];
String message = "Warning";
Icon icon = null;
switch (context){
case EXIT:
message = "getWantExit";
break;
case CLOSE:
message = "getWantCloseWindow";
break;
}
return JOptionPane.showOptionDialog(null,
bundle.getString(message),
bundle.getString("getWarning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
icon,
buttonLabels,
defaultOption);
}
}