title: Java Mouse position
body: <p>I've been trying to make this happen for weeks also I'm new to Java.</p>
  
  <p>I'm making a program that will have 6 different buttons I can click, and when I click the buttons It will allow me to click with the mouse anywhere on the screen to get the x, y position and save it so I can use the x,y positions with the Robot class to do various of tasks.</p>
  
  <p><img src="https://i.stack.imgur.com/hGaXI.png" alt="This is my gui"></p>
  
  <p>How should I build my code around each button to make it save the x,y to the specific button?</p>
  
  <p>I tried like this but as you probably can see I'm all lost..</p>
  
  <pre><code>import java.awt.*;
  import java.applet.*;
  import java.awt.event.*;
  
  public class setChords{//Start  class
  
      public void mouse1Chords(){ 
          int m1X = MouseInfo.getPointerInfo().getLocation().x; //Get location x
          int m1Y = MouseInfo.getPointerInfo().getLocation().y; //Get location y
          int mXY = m1X + m1Y;
      }
  
      public void mouse2Chords(){ 
          int m2X = MouseInfo.getPointerInfo().getLocation().x; //Get location x
          int m2Y = MouseInfo.getPointerInfo().getLocation().y; //Get location y
          int m2XY = m2X + m2Y;
      }
  
      public void mouse3Chords(){ 
          int m3X = MouseInfo.getPointerInfo().getLocation().x; //Get location x
          int m3Y = MouseInfo.getPointerInfo().getLocation().y; //Get location y
          int m3XY = m3X + m3Y;
      }
  
      public void mouse4Chords(){
          int m4X = MouseInfo.getPointerInfo().getLocation().x; //Get location x
          int m4Y = MouseInfo.getPointerInfo().getLocation().y; //Get location y
          int m4XY = m4X + m4Y;
      }
  
  
      public void mouse5Chords(){ 
          int m5X = MouseInfo.getPointerInfo().getLocation().x; //Get location x
          int m5Y = MouseInfo.getPointerInfo().getLocation().y; //Get location y
          int m5XY = m5X + m5Y;
      }
  
      public void mouse6Chords(){ 
          int m6X = MouseInfo.getPointerInfo().getLocation().x; //Get location x
          int m6Y = MouseInfo.getPointerInfo().getLocation().y; //Get location y
          int m6XY = m6X + m6Y;
      }
  
  }//end class
  </code></pre>
  
  <p>Thanks in advance &lt;3</p>