Browse Source

Changed Colors to cross and circle

feature_TicTacToe_Playfield
kfkama 3 years ago
parent
commit
003119fc27
  1. 31
      src/main/java/TicTacToe/Cell.java

31
src/main/java/TicTacToe/Cell.java

@ -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();
}
}
switch (playerID) {
case 1:
setBackground(new Color(255, 0, 0));
break;
case 2:
setBackground(new Color(0, 0, 255));
break;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
switch (playerID) {
case 1:
g2.drawOval(5, 5, 90, 90);
break;
case 2:
g2.drawLine(5, 5, 90, 90);
g2.drawLine(90, 5, 5, 90);
break;
} }
} }
protected void reset() { protected void reset() {
playerID = 0; playerID = 0;
setEnabled(true); setEnabled(true);
setBackground(new Color(255,255,255));
repaint();
} }
} }
Loading…
Cancel
Save