-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
46 lines (38 loc) · 1.58 KB
/
GamePanel.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
import javax.swing.*;
import java.awt.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.EmptyBorder;
public class GamePanel extends JPanel {
private SquareButton[] buttons;
private static final int PADDING = 10;
private static final Color BACKGROUND_COLOR = new Color(95, 67, 42);
private static final Color BORDER_COLOR = new Color(128, 80, 38);
public GamePanel() {
buttons = new SquareButton[64];
setLayout(new GridLayout(8, 8));
initializeButtons();
setBackground(BACKGROUND_COLOR);
setBorder(new EmptyBorder(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 :(
Border innerMargin = new LineBorder(BORDER_COLOR, 5);
setBorder(BorderFactory.createCompoundBorder(getBorder(), innerMargin));
}
private void initializeButtons() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
final Color color = (j % 2 + (i % 2) == 1) ? new Color(169, 121, 79) : new Color(235, 177, 126);
final int index = (i * 8) + j;
buttons[index] = new SquareButton("");
buttons[index].setBackground(color);
buttons[index].setFont(new Font("Arial", Font.PLAIN, 30));
add(buttons[index]);
}
}
}
public SquareButton[] getButtons() {
return buttons;
}
}