-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadGamePanel.java
More file actions
212 lines (177 loc) · 7.41 KB
/
Copy pathLoadGamePanel.java
File metadata and controls
212 lines (177 loc) · 7.41 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class LoadGamePanel extends JPanel implements MouseListener{
/*
------------------------
| Back Button |
| Title |
| FileName TextField |
| Error Label |
------------------------
*/
//Constants for panel layout
static int divisor = 4;
static final int SCREEN_WIDTH = 1500/2;
static final int SCREEN_HEIGHT= 1000/2;
static final int BOARD_WIDTH = 700/divisor;
static final int BOARD_HEIGHT = 600/divisor;
static final int UNIT_SIZE = 100/2;
static final int BOARD_X = 125;
static final int BOARD_Y = 0;
static final int GAME_UNITS = (BOARD_WIDTH * BOARD_HEIGHT) / UNIT_SIZE;
static int MULTIPLIER = 2;
static final int OFFSET = 35;
int clicks = 0;
static final Color COLOURS[] = {Color.red, Color.ORANGE, Color.yellow, Color.green, Color.cyan, Color.blue, new Color(75,0,130), };
static final Random rand = new Random();
static int idx = 0;
//rainbow background1
JPanel backGround1 = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(lightBlue);
g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//draw emptyCircles
int index = idx;
for (int j = 0; j < SCREEN_HEIGHT / UNIT_SIZE; j++) {
for (int i = 0; i < SCREEN_WIDTH / UNIT_SIZE; i++) {
index = (index+1)% COLOURS.length;
Color colour = COLOURS[index];
//Color colour = (tokenCount%2 == 0? Color.red: Color.yellow);
g.setColor(colour);
g.fillOval(i * UNIT_SIZE * MULTIPLIER-OFFSET, j * UNIT_SIZE * MULTIPLIER-OFFSET, UNIT_SIZE*MULTIPLIER, UNIT_SIZE*MULTIPLIER);
g.setColor(Color.BLACK);
g.drawOval(i * UNIT_SIZE * MULTIPLIER-OFFSET, j * UNIT_SIZE * MULTIPLIER-OFFSET, UNIT_SIZE*MULTIPLIER, UNIT_SIZE*MULTIPLIER);
}
}
idx+=6;
}
};
//rainbow background2
JPanel backGround2 = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(lightBlue);
g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//draw emptyCircles
int index = idx;
for (int j = 0; j < SCREEN_HEIGHT / UNIT_SIZE; j++) {
for (int i = 0; i < SCREEN_WIDTH / UNIT_SIZE; i++) {
index = (index+1)% COLOURS.length;
Color colour = COLOURS[index];
//Color colour = (tokenCount%2 == 0? Color.red: Color.yellow);
g.setColor(colour);
g.fillOval(i * UNIT_SIZE * MULTIPLIER-OFFSET, j * UNIT_SIZE * MULTIPLIER-OFFSET, UNIT_SIZE*MULTIPLIER, UNIT_SIZE*MULTIPLIER);
g.setColor(Color.BLACK);
g.drawOval(i * UNIT_SIZE * MULTIPLIER-OFFSET, j * UNIT_SIZE * MULTIPLIER-OFFSET, UNIT_SIZE*MULTIPLIER, UNIT_SIZE*MULTIPLIER);
}
}
idx+=6;
}
};
//all panels
JPanel titlePanel = new JPanel();
JPanel fileInputPanel = new JPanel();
JPanel errorPanel = new JPanel();
//All buttons used
JButton backMenuButton = new JButton("<--");
JButton MuteButton = new JButton("");
JButton SoundButton = new JButton(".");
//all labels
JLabel MuteLabel = new JLabel();
JLabel titleLabel = new JLabel("Connect 4");
JLabel errorLabel = new JLabel("File not found. Please try again.");
JLabel instructionLabel = new JLabel("Enter File Name: ");
JLabel SoundLabel = new JLabel();
//all fields
JTextField fileField = new JTextField(15);
//all fonts
Font fileNameFont = new Font("DialogInput", Font.BOLD, 30);
Font titleFont = new Font("DialogInput", Font.BOLD, 75);
//all colours
static final Color lightBlue = new Color(177, 225, 242);
LoadGamePanel() {
//load game panel set up and formatting
setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT));
setBackground(lightBlue);
setFocusable(true);
setLayout(null);
addMouseListener(this);
//Mute label and button set up and formatting
MuteLabel.setIcon(new ImageIcon("Mute.jpg"));
MuteButton.add(MuteLabel);
MuteButton.setBackground(Color.WHITE);
MuteButton.setBounds(UNIT_SIZE*13+10, UNIT_SIZE/2, UNIT_SIZE+25, UNIT_SIZE);
add(MuteButton);
MuteButton.setVisible(false);
//Sound label and button set up and formatting
SoundLabel.setIcon(new ImageIcon("Sound.jpg"));
SoundButton.add(SoundLabel);
SoundButton.setBackground(Color.WHITE);
SoundButton.setBounds(UNIT_SIZE*13+10, UNIT_SIZE/2, UNIT_SIZE+25, UNIT_SIZE);
add(SoundButton);
//back to menu button set up
backMenuButton.setBorder(BorderFactory.createLineBorder(Color.black));
backMenuButton.setFont(new Font("DialogInput", Font.BOLD, 15));
backMenuButton.setBounds(UNIT_SIZE/4, UNIT_SIZE/2, UNIT_SIZE+20, UNIT_SIZE);
add(backMenuButton);
//title panel set up
titlePanel.setBorder(BorderFactory.createLineBorder(Color.black));
titlePanel.setBackground(Color.white);
titlePanel.setBounds(UNIT_SIZE*2, UNIT_SIZE, UNIT_SIZE*11, UNIT_SIZE*2+10);
titleLabel.setFont(titleFont);
titlePanel.add(titleLabel);
add(titlePanel);
//instructions label label set up
instructionLabel.setFont(fileNameFont);
fileInputPanel.add(instructionLabel);
//file field set up
fileField.setFont(fileNameFont);
fileInputPanel.add(fileField);
//file input panel set up
fileInputPanel.setBorder(BorderFactory.createLineBorder(Color.black));
fileInputPanel.setBackground(Color.white);
fileInputPanel.setBounds(UNIT_SIZE, UNIT_SIZE*4, UNIT_SIZE*13, UNIT_SIZE+6);
add(fileInputPanel);
//error label
errorLabel.setFont(fileNameFont);
errorLabel.setForeground(Color.red);
errorPanel.add(errorLabel);
errorPanel.setBackground(Color.white);
errorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
errorPanel.setBounds(UNIT_SIZE, UNIT_SIZE*6, UNIT_SIZE*13, UNIT_SIZE);
add(errorPanel);
errorPanel.setVisible(false);
backGround1.setBounds(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
backGround2.setBounds(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
add(backGround1);
}
//Whenever the mouse is clicked, update the rainbow background
public void mouseClicked(MouseEvent e) {
if (clicks%2 == 0) {
remove(backGround1);
add(backGround2);
}
else {
add(backGround1);
remove(backGround2);
}
clicks++;
repaint();
revalidate();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}