-1

So this is my code:

public void mouseMoved(MouseEvent e){
    int mouseX = e.getX();
    int mouseXout = MouseInfo.getPointerInfo().getLocation().x;
    int width = pnlTrapIt.getWidth();

    int mouseY = e.getY();
    int mouseYout =  MouseInfo.getPointerInfo().getLocation().y; 
    int height= pnlTrapIt.getHeight();

    if(width < mouseXout && height < mouseYout) { 
        lblInfo.setText("The mouse is outside the program!");   
    }
}

Now what I want it to do is, apply this event to the entire screen resolution, as I want the program to do something when the mouse is outside the program's form. How can I apply this code to the entire screen even if the panel is smaller than the screen?

Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
Alpha2k
  • 2,212
  • 7
  • 38
  • 65
  • possible duplicate of [how to obtain mouse click coordinates outside my window in Java](http://stackoverflow.com/questions/2419555/how-to-obtain-mouse-click-coordinates-outside-my-window-in-java) –  Feb 16 '14 at 15:33

1 Answers1

0

It is possible though limited:

Add an AWTEventListener for focus events. As long as your app has focus before the button is clicked you'll receive a focus lost event. Then query for the pointer position.

The limitation is that, of course, your app loses focus. So depending on what you are ultimately trying to achieve this might not be useful.

Obviously, this will only register for the first click outside of the screen.

Read more here

Community
  • 1
  • 1
GreySwordz
  • 368
  • 1
  • 9