title: How to loop in a mouse event?
body: <p>How would would I loop mouse events? For example, I want to print out the x and y coordinates of the mouse position five times only. Any ideas how to do this?</p>
  
  <p>EDIT - I am sorry if I wasn't too clear. I don't want to print out the same coordinates five times- I am supposed to record the coordinates of where the user clicks on my JPanel. However, I don't want to record it every time the user clicks - I only want to record the coordinates a certain number of times, say, I want to record five different coordinates. After 5 clicks, the program stops recording. This is my code so far:</p>
  
  <pre><code>private void getcoordinates(MouseEvent e){   
  System.out.println(e.getX()+" - "+e.getY());
   }    
  
  
  private void recordCoordinates(final int x){
  addflagpanelRight.addMouseListener(new MouseAdapter() {
  @Override
  public void mousePressed(MouseEvent e) {
      //call the getcoordinates function -
      //now loop the getcoordinates function for each "x"??
  </code></pre>
  
  <p>}</p>
  
  <pre><code>   //Empty definitions
      @Override
      public void mouseClicked(MouseEvent e) {}
      @Override
      public void mouseReleased(MouseEvent e) {}  
      @Override
      public void mouseEntered(MouseEvent e) {}   
      @Override
      public void mouseExited(MouseEvent e) {}
  
  });
  }
  </code></pre>
  
  <p>Every time I try to loop the getcoordinates function I just get the same coordinates for each x. If x was set to 3, then when it loops 3 times, it prints 1 set of coordinates 3 times. Yes, I do realize the problem here, but how do I get around this?</p>