Java: Filling in a rectangle on a grid
<p>I'd like to begin by saying this is an assignment.  I do not want the answer spoon fed to me but I would like to know what is causing my problems.  </p>

<p>I am currently implementing Conway's Game of Life.  Clicking the cell should change the color, as to represent that cell being switched to an alive state.  if clicked again, it should return to the default color.  </p>

<p>When I click anywhere in the window, the program throws a Null Pointer Exception at line 56.  Have been stuck on this for the last day or so, so any help is appreciated.  Thanks! </p>

<p>Heres the code: </p>

<pre><code>import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class VisibleGrid extends JPanel implements MouseListener, KeyListener{ 

  CellGrid cellGrid;
  Graphics rect;

  public VisibleGrid(){
    addMouseListener(this);
    cellGrid = new CellGrid();
  }

  //Draw the grid of cells, 7px wide, 75 times to create 75x75 grid
  public void paint(Graphics g){
    for(int i=0; i&lt;525;i=i+7){
      for(int j = 0; j&lt;525; j=j+7){
        g.drawRect(i ,j,7,7);       
      }
    }   
  }

  //auxillary method called to fill in rectangles
  public void paint(Graphics g, int x, int y){
    g.fillRect(x, y, 7, 7);
    repaint();

  }

  //main method, adds this JPanel to a JFrame and sets up the GUI  
  public static void main(String[] args){
    JFrame j = new JFrame("Conway's Game of Life");
    j.setLayout(new BorderLayout());
    j.add(new VisibleGrid(), BorderLayout.CENTER);
    JTextArea info = new JTextArea("Press S to Start, E to End");
    info.setEditable(false);
    j.add(info, BorderLayout.SOUTH);
    j.setSize(530,565);
    j.setVisible(true);
  }

  //these methods are to satisfy the compiler/interface
  //Begin Mouse Events
  public void mouseExited(MouseEvent e){}
  public void mouseEntered(MouseEvent e){}
  public void mouseReleased(MouseEvent e){}
  public void mousePressed(MouseEvent e){}
  public void mouseClicked(MouseEvent e){
    //fill the selected rectangle
    rect.fillRect(e.getX(), e.getY(), 7,7); 
    repaint();

    //set the corresponding cell in the grid to alive
    int row = e.getY() /7;
    int column = e.getX() /7;
     cellGrid.getCell(row, column).setAlive(true);
  } 
  //End Mouse Events

//These methods are to satisfy the compiler/interface
//Begin KeyEvents
  public void keyReleased(KeyEvent e){}
  public void keyPressed(KeyEvent e){}
  public void keyTyped(KeyEvent e){}



}
</code></pre>
