-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pause.java~
74 lines (68 loc) · 2.22 KB
/
Pause.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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/**
* This is the Pause panel where the user chooses from a list of options.
*
* @author Eric Tu and Sejin Kwon
* @version 3
* @since June 1 2012
*/
public class Pause extends JPanel{
/**
* A list of buttons in the pause menu.
*/
private JButton pauseChoices [] = {new JButton("Resume"),new JButton("Restart"),new JButton("Quit")};
/**
* The class constructor.
*
* The loop does through all the buttons in the levelChoices array and adds them to the panel
* and adds a listener to them.
*/
public Pause(){
setFocusable (true);
setLayout (null);
pauseChoices [0].setMnemonic (KeyEvent.VK_F5);
pauseChoices [1].setMnemonic (KeyEvent.VK_F6);
pauseChoices [2].setMnemonic (KeyEvent.VK_F7);
for( int i = 0 ; i < pauseChoices.length ; i++){
pauseChoices [i].setBounds (270 + i*100, 25, pauseChoices [0].getPreferredSize ().width, pauseChoices [0].getPreferredSize ().height);
add(pauseChoices[i]);
pauseChoices[i].addActionListener(new PauseListener());
}
JLabel pause = new JLabel (new ImageIcon ("pause.png"));
pause.setBounds (0, 0, pause.getPreferredSize ().width, pause.getPreferredSize ().height);
add (pause);
updateUI();
}
/**
* This is the inner class that implements ActionListener.
*/
class PauseListener implements ActionListener{
/**
* This triggers when a button is pressed.
*
* If the user clicks Resume, the game resumes.
* If the user clicks Quit, the game goes back to the main menu.
*
* @param event This is the event triggered.
*/
public void actionPerformed(ActionEvent event){
if(event.getActionCommand().equals("Resume")){
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.GAME);
FrameApp.frame.add(FrameApp.s);
FrameApp.g.resumeGame ();
}
else if(event.getActionCommand().equals("Quit")){
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.MAINMENU);
FrameApp.g.pauseGame ();
}
else
{
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.LEVELSELECT);
}
FrameApp.frame.repaint();
FrameApp.mm.repaint();
}
}
}