//-------------------------------------------------------------------------------
//Programer: Aaron Eller
//Class GameInterface
//Purpose: this program displays a grid(world)
//
//---------------------------------------------------------------------------------

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class GameInterface extends Applet implements ActionListener
{
  Board game = new Board (this);
  
  Button one, ten, hundred, thousand, clear, reset, update;
  TextField lonelyField, crowdedField, birthField;
  Label cycle, rules, settings, birth, loneliness, crowding;
 
  Panel upper = new Panel();
  Panel lower = new Panel();

//--------------------------------------------------------------------------init  
  public void init()
  {
    setLayout(new BorderLayout());
    setBackground (Color.lightGray);
  //----------------------------------------------------------------------upper Panel
  // this panel has the different cycles and the clear button.  
    add("North",upper);
    upper.setLayout (new GridLayout (1,6));
    
    add ("Center", game);
    
    cycle = new Label ("Cycles:");
    upper.add (cycle);
    
    one = new Button ("1");
    upper.add(one);
    one.addActionListener (this);
     
    ten = new Button ("10");
    upper.add(ten);
    ten.addActionListener (this);
    
    hundred = new Button ("100");
    upper.add(hundred);
    hundred.addActionListener (this);
    
    thousand = new Button ("1000");
    upper.add(thousand);
    thousand.addActionListener (this);
    
    clear = new Button (" Clear");
    upper.add(clear);
    clear.addActionListener (this);
   //------------------------------------------------------------Lower Panel
   // this panel holds the rules, settings, reset and update 
   add("South",lower);
   lower.setLayout (new GridLayout (2,5));
    
   rules = new Label ("Rules");
   lower.add (rules);
   
   birth = new Label ("Birth >");
   lower.add (birth);
   
   loneliness= new Label ("Loneliness <  ");
   lower.add (loneliness);
   
   crowding = new Label ("Crowding >");
   lower.add (crowding);
   
   reset = new Button ("Reset");
   lower.add (reset);
   reset.addActionListener (this); 
    
   settings = new Label ("Settings");
   lower.add (settings);
   
   birthField = new TextField ("2");
   lower.add (birthField);
   birthField.addActionListener (this);
   
   lonelyField = new TextField ("2");
   lower.add (lonelyField);
   lonelyField.addActionListener (this);
   
   crowdedField = new TextField ("3");
   lower.add (crowdedField);
   crowdedField.addActionListener (this);
   
   update = new Button ("Update");
   lower.add (update);
   update.addActionListener (this); 
    
    
  }//end init
    
//---------------------------------------------------------------------------ActionPerformed
  public void actionPerformed ( ActionEvent event)
  {
    game.give_life(event);
    
    if (event.getSource() == clear)
    {
       game.clear();
    }  
    if (event.getSource() == one)
    {
      game.generation();
    }
          
  }//end actionPerformed
  
}//end gamenterface

