How do I know if the mouse if out of the window I made and from which side it exited. I'm making a classic pong game and when I move my mouse out too fast, the 'thing' stays some pixels in. I'd like it to move to the edge of the window where it exited.
private class MouseMotion extends MouseAdapter{
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
int x = e.getX();
p1.move(x);
}
}
and the move function
public void move(int x) {
if (x < 0 ) {
this.x = 0;
}else if(x+width > Main.screenSize.width - 1){
this.x = Main.screenSize.width - width - 1;
} else {
this.x = x;
}
}
I just need to know a way to know if the mouse is out of the window.