Say I\'m in a Java Swing JFrame. I click my mouse. I want to get the location of the mouse click within the GUI. In java, the line
int mouse
From MouseListener methods you can do:
@Override
public void mouseClicked(MouseEvent e) {
int x=e.getX();
int y=e.getY();
System.out.println(x+","+y);//these co-ords are relative to the component
}
Simply add this to your Component by:
component.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
});
Reference: