title: Conways game of life
body: <blockquote>
    <p>Create a method called live that accepts a row and column, then returns a boolean that determines if an existing cell in that location will live or die (or a cell will be created) according to a set of rules (Conway’s game of Life).  When checking the number of cells around a cell, be careful to consider the boundaries of the array.</p>
  </blockquote>
  
  <p>I already have the method but I don't know what to do inside that method. </p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  import java.awt.event.*;  // Needed for ActionListener
  import javax.swing.event.*;  // Needed for ActionListener
  
  class LifeSimulationGUIDemo extends JFrame
  {
      static Colony colony = new Colony (0.5);
      static Timer t;
  
      //======================================================== constructor
      public LifeSimulationGUIDemo ()
      {
          // 1... Create/initialize components
          BtnListener btnListener = new BtnListener (); // listener for all buttons
  
          JButton simulateBtn = new JButton ("Simulate");
          simulateBtn.addActionListener (btnListener);
  
          // 2... Create content pane, set layout
          JPanel content = new JPanel ();        // Create a content pane
          content.setLayout (new BorderLayout ()); // Use BorderLayout for panel
          JPanel north = new JPanel ();
          north.setLayout (new FlowLayout ()); // Use FlowLayout for input area
  
          DrawArea board = new DrawArea (500, 500);
  
          // 3... Add the components to the input area.
  
          north.add (simulateBtn);
  
          content.add (north, "North"); // Input area
          content.add (board, "South"); // Output area
  
          // 4... Set this window's attributes.
          setContentPane (content);
          pack ();
          setTitle ("Life Simulation");
          setSize (510, 570);
          setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          setLocationRelativeTo (null);           // Center window.
      }
  
      class BtnListener implements ActionListener 
      {
          public void actionPerformed (ActionEvent e)
          {
              if (e.getActionCommand ().equals ("Simulate"))
              {
                  Movement moveColony = new Movement (); // ActionListener for timer
                  t = new Timer (200, moveColony); // set up Movement to run every 200 milliseconds
                  t.start (); // start simulation
              }
              repaint ();            // refresh display of colony
          }
      }
  
      class DrawArea extends JPanel
      {
          public DrawArea (int width, int height)
          {
              this.setPreferredSize (new Dimension (width, height)); // size
          }
  
          public void paintComponent (Graphics g)
          {
              colony.show (g); // display current state of colony
          }
      }
  
      class Movement implements ActionListener
      {
          public void actionPerformed (ActionEvent event)
          {
              colony.advance (); // advance to the next time step
              repaint (); // refresh 
          }
      }
  
      //======================================================== method main
      public static void main (String[] args)
      {
          LifeSimulationGUIDemo window = new LifeSimulationGUIDemo ();
          window.setVisible (true);
      }
  }
  
  class Colony
  {
  
  
      private boolean grid[] [];
  
      public  boolean live ( int row, int column)
      {
  
  
      }
  
  
  
      public Colony (double density)
      {
          grid = new boolean [100] [100];
          for (int row = 0 ; row &lt; grid.length ; row++)
              for (int col = 0 ; col &lt; grid [0].length ; col++)
                  grid [row] [col] = Math.random () &lt; density;
      }
  
      public void show (Graphics g)
      {
          for (int row = 0 ; row &lt; grid.length ; row++)
              for (int col = 0 ; col &lt; grid [0].length ; col++)
              {
                  if (grid [row] [col]) // life
                      g.setColor (Color.black);
                  else
                      g.setColor (Color.white);
                  g.fillRect (col * 5 + 2, row * 5 + 2, 5, 5); // draw life form
              }
      }
  
      public void advance ()
      {
      }
  }
  </code></pre>