-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerPanel.java
76 lines (66 loc) · 1.67 KB
/
PlayerPanel.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
/**
*makes a panel of buttons
* @author blybr
*/
public class PlayerPanel extends JPanel{
private JButton[][] button = new JButton[4][4];
private ActionListener[][] clicks = new ClickListener[4][4];
private BoardComponent board;
/**
* makes buttons in appropriate order to match grid
* @param b
*/
public PlayerPanel(BoardComponent b)
{
this.setLayout(new GridLayout(4,4));
for (int i = 4; i > 0; i--)
{
for(int j = 1; j < 5; j++)
{
String name= Integer.toString(j) + "-" + Integer.toString(i);
button[j - 1][i - 1] = new JButton(name);
add(button[j - 1][i - 1]);
}
}
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
clicks[i][j] = new ClickListener((i + 1) * 75, 400 - (j * 75));
button[i][j].addActionListener(clicks[i][j]);
}
}
board = b;
}
/**
* Listeners to cause circles to appear on frame
*/
public class ClickListener implements ActionListener {
private int n=1;
private final int xCoord;
private final int yCoord;
private boolean colour;
public ClickListener(int x, int y)
{
xCoord=x;
yCoord=y;
}
@Override
// makes beads with coordinates
public void actionPerformed(ActionEvent e)
{
board.getPeg(xCoord, yCoord).addBead(); // allows bead to be shown on peg
board.paintAgain(); // repaints beads that have been added
}
}
}