kfkama
3 years ago
2 changed files with 61 additions and 5 deletions
@ -1,13 +1,40 @@ |
|||||
package TicTacToe; |
package TicTacToe; |
||||
|
import java.awt.Color; |
||||
|
import java.awt.event.ActionEvent; |
||||
|
import java.awt.event.ActionListener; |
||||
|
|
||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||
|
|
||||
public class cell extends JButton { |
public class cell extends JButton { |
||||
|
|
||||
int value = 0; |
int value = 0; |
||||
|
private TicTacToeGame ttt; |
||||
|
|
||||
public cell() { |
|
||||
|
public cell(TicTacToeGame _ttt) { |
||||
|
ttt = _ttt; |
||||
|
|
||||
|
addActionListener(new ActionListener() { |
||||
|
@Override |
||||
|
public void actionPerformed(ActionEvent e) { |
||||
|
OnMouseClick(); |
||||
|
} |
||||
|
}); |
||||
} |
} |
||||
|
|
||||
|
|
||||
|
protected void OnMouseClick() { |
||||
|
value = ttt.player; |
||||
|
ttt.endTurn(); |
||||
|
switch (value) { |
||||
|
case 1: setBackground(new Color(255,0,0)); |
||||
|
break; |
||||
|
case 2: setBackground(new Color(0,0,255)); |
||||
|
break; |
||||
|
default: ; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue