Repository navigation
Expand file tree
/
Copy pathSelectStadium.java
More file actions
122 lines (98 loc) · 4.31 KB
/
Copy pathSelectStadium.java
File metadata and controls
122 lines (98 loc) · 4.31 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
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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**Allows the players to select a stadium by pressing a corresponding button
* - these buttons will change the background image of the game*/
public class SelectStadium implements ActionListener {
// button used to select a stadium
JButton oldTraffordButton;
JButton stamfordBridgeButton;
JButton campNouButton;
JButton santiagoBernabeuButton;
// paths to each stadium image, that will be used to pass through as a parameter
public static String oldTrafford = "data/stadiums/OldTrafford.png";
public static String stamfordBridge = "data/stadiums/StamfordBridge.png";
public static String CampNou = "data/stadiums/CampNou.png";
public static String santiagoBernabeu = "data/stadiums/SantiagoBernabeu.png";
private Game oldTraffordGame;
private Game stamfordBridgeGame;
private Game santiagoGame;
private Game campNouGame;
// CONSTRUCTOR
public SelectStadium(){
final JFrame frame = new JFrame("SelectStadium");
JPanel panel = new JPanel();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.setLocationByPlatform(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
panel.setLayout(null);
// creating and adding the buttons to panel
Icon oT = new ImageIcon("data/buttonIcons/OldTrafford.png");
oldTraffordButton = new JButton(oT);
panel.add(oldTraffordButton);
Icon sB = new ImageIcon("data/buttonIcons/StamfordBridge.png");
stamfordBridgeButton = new JButton(sB);
panel.add(stamfordBridgeButton);
Icon cN = new ImageIcon("data/buttonIcons/CampNou.png");
campNouButton = new JButton(cN);
panel.add(campNouButton);
Icon sBer = new ImageIcon("data/buttonIcons/SantiagoBernabeu.png");
santiagoBernabeuButton = new JButton(sBer);
panel.add(santiagoBernabeuButton);
// set location of the buttons
oldTraffordButton.setBounds(25,110,200,100);
stamfordBridgeButton.setBounds(250,110,200,100);
campNouButton.setBounds(25,250,200,100);
santiagoBernabeuButton.setBounds(250,250,200,100);
// SELECT STADIUM header
ImageIcon textImg = new ImageIcon("data/text/selectStadium.png");
JLabel text = new JLabel("",textImg,JLabel.CENTER);
text.setBounds(0,0,500,100);
panel.add(text);
// background
ImageIcon img = new ImageIcon("data/stadiums/grass.png");
JLabel background = new JLabel("",img,JLabel.CENTER);
background.setBounds(0,0,500,500);
panel.add(background);
frame.setVisible(true);
buttonListeners();
}
// events that occur when the buttons are pressed
public void buttonListeners() {
ActionListener oldTButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
oldTraffordGame = new Game(oldTrafford); // starts a new game with Old Trafford as the background
}
};
ActionListener stamBridgeButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stamfordBridgeGame = new Game(stamfordBridge);
}
};
ActionListener campButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
campNouGame = new Game(CampNou);
}
};
ActionListener santiagoBernButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
santiagoGame = new Game(santiagoBernabeu);
}
};
// adds appropriate action listeners to the buttons
oldTraffordButton.addActionListener(oldTButton);
stamfordBridgeButton.addActionListener(stamBridgeButton);
campNouButton.addActionListener(campButton);
santiagoBernabeuButton.addActionListener(santiagoBernButton);
}
@Override
public void actionPerformed(ActionEvent e) {
}
}