forked from pr-1/Beginner-TicTacToe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XOButton.java
36 lines (32 loc) · 800 Bytes
/
XOButton.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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by prince on 4/6/17.
*/
public class XOButton extends JButton implements ActionListener{
ImageIcon X,O;
byte value=0;
public XOButton(){
X=new ImageIcon(this.getClass().getResource("X.png"));
O=new ImageIcon(this.getClass().getResource("O.jpeg"));
this.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
value++;
value%=3;
switch (value)
{
case 0:
setIcon(null);
break;
case 1:
setIcon(X);
break;
case 2:
setIcon(O);
break;
}
}
}