package lab00;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;

import javax.swing.JButton;

public class Square extends JButton {

	private static final long serialVersionUID = 1L;
	TicTacToe game;
	
	public Square(TicTacToe game) {
		this.game = game;
		setForeground(Color.GREEN);
		setFont(getFont().deriveFont((float) 40.0));
		setPreferredSize(new Dimension(70,70));
		setMargin(new Insets(-30,-30,-30,-30));
		setText(" ");
		addActionListener( (e)-> { 
			choose("X"); 
			if (game.checkWinner()) return;
			game.computerTurn();
		});
	}
	
	public void choose(String val) {
		if (val.equals("X")) this.setForeground(Color.blue);
		else this.setForeground(Color.red);
		setText(val);
		setEnabled(false);
	}
	
}
