1

I've been trying to make this happen for weeks also I'm new to Java.

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.

This is my gui

How should I build my code around each button to make it save the x,y to the specific button?

I tried like this but as you probably can see I'm all lost..

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

Thanks in advance <3

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
Jake Steel
  • 11
  • 2
  • 1
    Your code does not help much because we have no idea how it is invoked and what the purpose of each method is. the weirdest thing is this computation `m1X+m1Y`, what is its purpose? – Guillaume Polet Mar 19 '12 at 17:15
  • and nothing to do with Applet declared in the code and sticked image in the question – mKorbel Mar 19 '12 at 17:18
  • AFAIU the `Robot` can make clicks outside the GUI, but not detect them. My approach to this situation is to grab a screenshot and put it in a label with a mouse listener, then show it to the user & ask them to select a point on the label, much as shown in [this answer](http://stackoverflow.com/a/6092439/418556). – Andrew Thompson Mar 19 '12 at 17:20

0 Answers0