import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JButton;

public class Grid
{

	JFrame frame;
	JButton squares[][];
	
	public Grid(int x, int y) 
	{
		
		squares = new JButton[x][y];		
		
		frame = new JFrame("Conway's");
	    frame.setSize(450, 450);
	    frame.setLayout(new GridLayout(x, y));
	    	    
	    for (int i = 0; i < x; i++) {
	        for (int j = 0; j < y; j++) {
	            squares[i][j] = new JButton();
	            squares[i][j].setBackground(Color.white);
	            frame.add(squares[i][j]);
	        }
	    }
	    
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.setVisible(true);	    
	}
	
	public void alive(int x, int y,int tur)
	{
		if (tur == 1)
			squares[x][y].setBackground(Color.black);
		else if (tur == 2)
			squares[x][y].setBackground(Color.green);
		else if (tur == 3)
			squares[x][y].setBackground(Color.blue);
		
		frame.repaint();
	}
	
	public void dead(int x, int y)
	{
		squares[x][y].setBackground(Color.white);
		frame.repaint();
	}
	
}