Sorry in advance for title, I don't quite know what this is called.
I'm trying to set up my JFrame so that when it crosses past the screens width (or height), it stops moving. This is the code I have so far...
public void moverMouseDragged(java.awt.event.MouseEvent evt) {
int x = evt.getXOnScreen()-xMouse;
int y = evt.getYOnScreen()-yMouse;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width2 = (int) screenSize.getWidth();
int height2 = (int) screenSize.getHeight();
if(this.getX()<0){x=0;}
if(this.getY()<0){y=0;}
if((this.getX()+width)>width2){x=width2;}
if((this.getY()+height)>height2){y=height2;}
this.setLocation(x, y);
System.out.println(this.getY()+"\n"+this.getX());
}
public void moverMousePressed(java.awt.event.MouseEvent evt) {
xMouse = evt.getX();
yMouse = evt.getY();
}
This works only for the top, and left side of my screen. Its full of glitches, and I honestly don't know where to go from here.