-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resume.java
executable file
·157 lines (132 loc) · 3.86 KB
/
Resume.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
public class Resume extends Menu implements Action {
ImageIcon Resume, Resumeh, Restart, Restarth;
{
//reading images
try {
Resume = new ImageIcon("resources\\resume.png");
Resumeh = new ImageIcon("resources\\resumeh.png");
Restart = new ImageIcon("resources\\restart.png");
Restarth = new ImageIcon("resources\\restarth.png");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "image not found");
}
//assigning images to first two buttons
jb[0].setIcon(Resume);
jb[1].setIcon(Restart);
}
//adding key listener through key bindings
{
InputMap mp = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
mp.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "key");
ActionMap act = this.getActionMap();
act.put("key", this);
}
public void mouseClicked(MouseEvent e) {
// When mouse clciked
// If button is first button ResumeGame button then resume game
if (e.getComponent() == jb[0]) {
Methods.fm.setVisible(false);
Methods.fm.removeAll();
Methods.fm.dispose();
GameMode.gamePanel.pause = false;
this.clip.stop();
GameMode.gamePanel.clip.start();
}
// If button is Second button Restart Game button then restart game
if (e.getComponent() == jb[1]) {
GameMode.gamePanel.setVisible(false);
GameMode.gamePanel = null;
if(GameMode.mode==1)
GameMode.gamePanel = new Paints();
if(GameMode.mode==2)
GameMode.gamePanel = new Paints2();
GameMode.gamePanel.pause = false;
GameMode.gamePanel.setVisible(true);
Methods.fm.dispose();
this.clip.stop();
this.setVisible(false);
TrafficMania.frame.add(GameMode.gamePanel);
TrafficMania.frame.revalidate();
}
if (e.getComponent() == jb[2]) {
jb[2].setIcon(instructionsh);
fm = new JFrame();
fm.add(new Instructions());
fm.setUndecorated(true);
fm.setExtendedState(JFrame.MAXIMIZED_BOTH);
fm.setVisible(true);
}
if (e.getComponent() == jb[3]) {
// Setting visibility and focus
Methods.fm.removeAll();
Methods.fm.dispose();
GameMode.gamePanel.setVisible(false);
GameMode.gamePanel.pause = false;
this.clip.stop();
TrafficMania.frame.remove(GameMode.gamePanel);
TrafficMania.frame.add(new Menu());
}
}
@Override
public void mouseEntered(MouseEvent e) {
// Changing images of buttons when mouse entered to make hover effect
if (e.getComponent() == jb[0]) {
jb[0].setIcon(Resumeh);
repaint();
}
if (e.getComponent() == jb[1]) {
jb[1].setIcon(Restarth);
}
if (e.getComponent() == jb[2]) {
jb[2].setIcon(instructionsh);
}
if (e.getComponent() == jb[3]) {
jb[3].setIcon(Exith);
}
}
@Override
public void mouseExited(MouseEvent e) {
// Restoring images of JLabes when mouse removed
if (e.getComponent() == jb[0]) {
jb[0].setIcon(Resume);
repaint();
}
if (e.getComponent() == jb[1]) {
jb[1].setIcon(Restart);
}
if (e.getComponent() == jb[2]) {
jb[2].setIcon(instructions);
}
if (e.getComponent() == jb[3]) {
jb[3].setIcon(Exit);
}
}
// adding action of escape button
@Override
public void actionPerformed(ActionEvent arg0) {
Methods.fm.setVisible(false);
Methods.fm.removeAll();
Methods.fm.dispose();
GameMode.gamePanel.pause = false;
this.clip.stop(); //stopping music
GameMode.gamePanel.clip.start();
}
@Override
public Object getValue(String arg0) {
return null;
}
@Override
public void putValue(String arg0, Object arg1) {
}
}