import java.awt.*;

public class Cell extends Button

// initialize variables

{
   static final int DEAD = 0;
   static final Color DEAD_COLOR = Color.black;
   static final int ALIVE = 1;
   static final Color ALIVE_COLOR = Color.red;
   private int state; 
   private int temp;   

// constructor to initialize the state of each instance of Cell as it // is created.

   public Cell (Interface game)
   {

      temp = DEAD;
      state = DEAD;
      setBackground (DEAD_COLOR);
      addActionListener (game);

   } 
   public int getState ()
   {
      return state;
   }  

// resets the state of the cell

   public void clear ()
   {
      temp = DEAD;
      state = DEAD;
      setBackground (DEAD_COLOR);
   }

// marks that the cell has been changed without actually changing the // state, so that the original state can still be used in the rules.

      public void change2 ()
   {
      
      if (state == DEAD)
      {
         temp = ALIVE;         
      }
      else
      if (state == ALIVE)
      {
         temp = DEAD;
      }
   }  

// changes the cells state when the user clicks on it

      public void change ()
   {
      
      if (state == DEAD)
      {
         temp = ALIVE;
         state = ALIVE;
         setBackground (ALIVE_COLOR);
         
      }
      else
      if (state == ALIVE)
      {
         temp = DEAD;
         state = DEAD;
         setBackground (DEAD_COLOR);
	
      }
   }  

// changes the state of the marked cells to that which they were marked // for

     public void switchem ()  
      {
        if (temp == DEAD)
        {
          state = DEAD;
          setBackground (DEAD_COLOR);
        }
        else
        if (temp == ALIVE)
        {
          state = ALIVE;
          setBackground (ALIVE_COLOR);
     
        }
      }
}
