title: Finding Mouse Position relative to a panel
body: <p>I'm trying to get the mouse's position within a panel, as in the top left of the panel = x/y 0,0.</p>
  
  <p>What I have at the minute gives the position on the entire screen, so depending on where the panel (which is in a frame) is on the screen, the coordinates are different. I guess you could add to the x/y co-ordinates to account for this, but this seems like a messy solution. Can anyone help? </p>
  
  <p>Here's the mouseListener I'm using, which has been added to the panel.</p>
  
  <pre><code>private class MouseListener extends MouseAdapter 
  {
      public void mouseClicked(MouseEvent e) 
      {
          // Finds the location of the mouse
          PointerInfo a = MouseInfo.getPointerInfo();
          Point b = a.getLocation();
  
          // Gets the x -&gt; and y co-ordinates
          int x = (int) b.getX();
          int y = (int) b.getY();
          System.out.println("Mouse x: " + x);
          System.out.println("Mouse y: " + y);
  
          // Determines which tile the click occured on
          int xTile = x/tileSize;
          int yTile = y/tileSize;
  
          System.out.println("X Tile: " + xTile);
          System.out.println("Y Tile: " + yTile);
  
      }
  }
  </code></pre>