-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
48 lines (41 loc) · 1.06 KB
/
Square.java
File metadata and controls
48 lines (41 loc) · 1.06 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
package reversi;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Square extends JPanel {
int player;
int i,j;
IController cont;
int color;
Square(int player, int i, int j, IController cont) {
this.player=player;
this.i=i;
this.j=j;
this.cont=cont;
this.color=0;
setLayout(new BorderLayout());
setBackground(Color.GREEN);
setBorder(BorderFactory.createLineBorder(Color.BLACK));
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e){
cont.squareSelected(player, i, j);
}
});
}
public void addCounter(int color) {
/*Remove other counters*/
this.color=color;
for (Component c : getComponents())
remove(c);
add(new Counter(color));
}
public int[] getPos(){
int[] ret = {i,j};
return ret;
}
public int getCol(){
return color;
}
}