-
Notifications
You must be signed in to change notification settings - Fork 9
/
Grid_button.java
52 lines (42 loc) · 1.11 KB
/
Grid_button.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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class Grid_button extends JButton {
/**
*
*/
private static final long serialVersionUID = 1L;
private final int fX;
private final int fY;
public Grid_button(final int x, final int y) {
fX= x;
fY= y;
//fModel= model;
addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
boolean text = false;
if (TicTacToe.turn == 1 && getText()=="")
{
setText("X");
text=true;
}
else if (getText()=="")
{
setText("O");
text = true;
}
if (text){
try {
TicTacToe.user_vs_user(fX,fY);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
TicTacToe.turn = TicTacToe.turn*-1;
}
}
});
}
}