title: How do I know if someone clicks in a specific panel?
body: <p>so this is my problem. I have an 8*8 grid of panels, all white. Then, when one of them is clicked, it's supposed to change to a random color. The only problem I have right now is that I don't know how to see if the user clicked their mouse in a specific panel. Here is the code I have so far (I'm going to implement the random element afterwards)
  `</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  public class GridOfPanels extends JPanel{
      int x, y;
      public GridOfPanels(){
          JPanel content = new JPanel(new GridLayout(8,8));
          for(int i = 0; i &lt; 64; i++){
              JPanel panel = new JPanel();
              panel.setBackground(Color.white);
              content.add(panel);
          }
          this.add(content);
      }
      public GridOfPanels(Color backColor){
          setBackground(backColor);
          addMouseListener(new PanelListener());
          x = 200;
          y = 200;
      }
      private class PanelListener extends MouseAdapter{
          public void mousePressed(MouseEvent e){
              x = e.getX();
              y = e.getY();
              repaint();
          }
      }
      public static void main(String[] args){
          JFrame theGUI = new JFrame();
          theGUI.setTitle("Grid");
          theGUI.setVisible(true);
          theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          theGUI.setSize(400,400);
          Rectangle z = new Rectangle(x, y, 50, 50);
      }
  }
  </code></pre>
  
  <p>`</p>