-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelSelect.java~
88 lines (83 loc) · 3.2 KB
/
LevelSelect.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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/**
* This is the LevelSelect panel where the user chooses a level.
*
* @author Eric Tu and Sejin Kwon
* @version 3
* @since June 1 2012
*/
public class LevelSelect extends JPanel {
/**
* This is an array of JButtons for the selections.
*/
JButton levelChoices [] = {new JButton(new ImageIcon ("Easy.png")), new JButton(new ImageIcon ("Medium.png")), new JButton(new ImageIcon ("Hard.png"))};
/**
* 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 LevelSelect(){
setLayout (null);
JLabel level = new JLabel (new ImageIcon ("Difficulty.png"));
level.setBounds (5, 295, level.getPreferredSize ().width, level.getPreferredSize ().height);
add (level);
levelChoices [0].setRolloverIcon (new ImageIcon ("Easyrollover.png"));
levelChoices [1].setRolloverIcon (new ImageIcon ("Medium rollover.png"));
levelChoices [2].setRolloverIcon (new ImageIcon ("Hardrollover.png"));
String [] levels = {"Easy", "Medium", "Hard"};
for(int i = 0 ; i < levelChoices.length ; i++){
add(levelChoices[i]);
levelChoices[i].addActionListener(new LevelListener());
levelChoices [i].setActionCommand(levels[i]);
levelChoices[i].setOpaque(false);
levelChoices[i].setContentAreaFilled(false);
levelChoices[i].setBorderPainted(false);
levelChoices[i].setFocusable(false);
levelChoices[i].setBounds(275,i*185 + 10,100,75);
}
JButton back = new JButton (new ImageIcon ("Back.png"));
back.setOpaque (false);
back.setContentAreaFilled (false);
back.setBorderPainted (false);
back.setFocusable (false);
back.setRolloverIcon (new ImageIcon ("Backrollover.png"));
back.setBounds (480, 10, back.getPreferredSize ().width, back.getPreferredSize ().height);
add (back);
back.addActionListener (new LevelListener ());
updateUI ();
}
/**
* This is an inner class that implements ActionListener.
*/
class LevelListener implements ActionListener{
/**
* This method is triggered when a button is pressed.
*
* Depending on what level the user chooses, the string for the level will be changed
* and so will the panel.
* If the user clicks back, it will go back to the main menu.
*
* @param event The event that is triggered.
*/
public void actionPerformed(ActionEvent event){
if(event.getActionCommand().equals("Easy")){
Game.difficulty =1;
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.COLOURSELECT);
}
else if(event.getActionCommand().equals("Medium")){
Game.difficulty =2;
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.COLOURSELECT); // FrameApp.frame.add(new ScorePanel());
}
else if(event.getActionCommand().equals("Hard")){
Game.difficulty =3;
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.COLOURSELECT); // FrameApp.frame.add(new ScorePanel());
}
else{
FrameApp.cardLayout.show(FrameApp.mainPanel, FrameApp.MAINMENU);
FrameApp.mainPanel.repaint();}
}
}
}