JFrame simple moving oval moving game positioning fails? <p>I have a game start I've made, basically a oval, and I can move it anywhere with the keyboard key arrows.</p> <p>I dont want to allow it to exit the frame, so I check if X is less than 0, return if higher than width return, same for y.</p> <p>But it doesn't work for &lt; width and > height, I can go to the right and bottom until it exits the frame, why?</p> <p>This is the code, (I didnt use myHeight, myWidth I manually put the sizes, the sizes are 765, 500).</p> <pre><code>public void movePlayer(int x, int y) { System.out.println(myPlayer.getX()); if (x == 0) { if (y + myPlayer.getY() &gt; 500 || y + myPlayer.getY() &lt; 0) { return; } this.myPlayer.moveY(y); } else if (y == 0) { if (x + myPlayer.getX() &gt; 765 || x + myPlayer.getX() &lt; 0) { return; } this.myPlayer.moveX(x); } } </code></pre> <p>Why is this happening?</p>