- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
Latest commit
46 lines (38 loc) · 1.58 KB
/
Copy pathGamePanel.java
File metadata and controls
46 lines (38 loc) · 1.58 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
importjavax.swing.*;
importjava.awt.*;
importjavax.swing.border.Border;
importjavax.swing.border.LineBorder;
importjavax.swing.border.EmptyBorder;
publicclassGamePanelextendsJPanel {
privateSquareButton[] buttons;
privatestaticfinalintPADDING = 10;
privatestaticfinalColorBACKGROUND_COLOR = newColor(95, 67, 42);
privatestaticfinalColorBORDER_COLOR = newColor(128, 80, 38);
publicGamePanel() {
buttons = newSquareButton[64];
setLayout(newGridLayout(8, 8));
initializeButtons();
setBackground(BACKGROUND_COLOR);
setBorder(newEmptyBorder(PADDING, PADDING, PADDING, PADDING));
// Add an inner margin to thicken the cell borders outer rim, so it looks like
// the board is made of lines instead of cells
// I don't like working with java swing :(
BorderinnerMargin = newLineBorder(BORDER_COLOR, 5);
setBorder(BorderFactory.createCompoundBorder(getBorder(), innerMargin));
}
privatevoidinitializeButtons() {
for (inti = 0; i < 8; i++) {
for (intj = 0; j < 8; j++) {
finalColorcolor = (j % 2 + (i % 2) == 1) ? newColor(169, 121, 79) : newColor(235, 177, 126);
finalintindex = (i * 8) + j;
buttons[index] = newSquareButton("");
buttons[index].setBackground(color);
buttons[index].setFont(newFont("Arial", Font.PLAIN, 30));
add(buttons[index]);
}
}
}
publicSquareButton[] getButtons() {
returnbuttons;
}
}