title: Change the color of a certain pane in gridlayout
body: <p>So, what I want to happen is for every box to be white but when the user clicks on one of the boxes in the grid, it will change to a randomly generated color. I know how to write the code for the randomly generated color, but I'm not sure how to make it so that the program chooses the correct panel to change its color. Here is what i have so far: </p>
  
  <p>Client</p>
  
  <pre><code>import javax.swing.*;    
  import java.awt.*;
  import java.util.Random;       
  
  public class Prog3
  {
     public static void main(String[] args)
     {
         int rows=8;
         int cols=8;
         JFrame theGUI = new JFrame();
         theGUI.setTitle("GUI Example");
         theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container pane = theGUI.getContentPane();
         pane.setLayout(new GridLayout(rows, cols,5,5));
  
         for (int i = 1; i &lt; rows * cols; i++)
         {
             Color backColor = Color.white;
             Prog3_Server panel = new Prog3_Server(backColor,50,50);
             pane.add(panel);
         }
         theGUI.pack();
         theGUI.setVisible(true);
      }
  }
  </code></pre>
  
  <p>Server</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Prog3_Server extends JPanel
  {
      public static void main(String[] args)
      {
          JFrame theGUI = new JFrame();
          theGUI.setTitle("GUI Example");
          theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Prog3_Server panel = new Prog3_Server(Color.white, 200, 200);
          Container pane = theGUI.getContentPane();
          pane.add(panel);
          theGUI.pack();
          theGUI.setVisible(true);
      }
  
     // Client provides color and preferred width and height
     public Prog3_Server(Color backColor, int width, int height){
        setBackground(backColor);
        setPreferredSize(new Dimension(width, height));
     }
  
     // Client provides color 
     // Preferred width and height are 0, 0 by default   
     public Prog3_Server(Color backColor){
        setBackground(backColor);
     }    
  }
  </code></pre>
  
  <p>Any ideas on how i would use mouse events to make sure the right panel is changed from white to a random color?</p>