|
@ -1,6 +1,8 @@ |
|
|
package TicTacToe; |
|
|
package TicTacToe; |
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
import java.awt.Color; |
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionListener; |
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
@ -13,7 +15,7 @@ public class Cell extends JButton { |
|
|
|
|
|
|
|
|
public Cell(TicTacToeGame _ttt) { |
|
|
public Cell(TicTacToeGame _ttt) { |
|
|
ttt = _ttt; |
|
|
ttt = _ttt; |
|
|
setBackground(new Color(255,255,255)); |
|
|
|
|
|
|
|
|
setBackground(new Color(255, 255, 255)); |
|
|
|
|
|
|
|
|
addActionListener(new ActionListener() { |
|
|
addActionListener(new ActionListener() { |
|
|
@Override |
|
|
@Override |
|
@ -28,22 +30,31 @@ public class Cell extends JButton { |
|
|
playerID = ttt.playerID; |
|
|
playerID = ttt.playerID; |
|
|
ttt.endTurn(); |
|
|
ttt.endTurn(); |
|
|
setEnabled(false); |
|
|
setEnabled(false); |
|
|
|
|
|
repaint(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
|
|
super.paintComponent(g); |
|
|
|
|
|
Graphics2D g2 = (Graphics2D) g; |
|
|
|
|
|
|
|
|
switch (playerID) { |
|
|
switch (playerID) { |
|
|
case 1: |
|
|
case 1: |
|
|
setBackground(new Color(255, 0, 0)); |
|
|
|
|
|
|
|
|
g2.drawOval(5, 5, 90, 90); |
|
|
break; |
|
|
break; |
|
|
case 2: |
|
|
case 2: |
|
|
setBackground(new Color(0, 0, 255)); |
|
|
|
|
|
|
|
|
g2.drawLine(5, 5, 90, 90); |
|
|
|
|
|
g2.drawLine(90, 5, 5, 90); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void reset() { |
|
|
protected void reset() { |
|
|
playerID = 0; |
|
|
playerID = 0; |
|
|
setEnabled(true); |
|
|
setEnabled(true); |
|
|
setBackground(new Color(255,255,255)); |
|
|
|
|
|
|
|
|
repaint(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |