You have some poor style in that predicate method. You can see what better style would look like in this
style guide §10.5.2.
It looks as though you were touching the right edge and not moving away from it.
I still think you need a Ball class separate from the class representing the Court. Each time you run the program (every 30ms), you call a move method on the ball. I think you are going to have to delete lots of the current class, I am afraid.
The ball needs to “know” the size of the court. I have thought of two ways.
1: You might pass a court instance to the ball instance; then the ball can tell the size of the court and whether it has reached the edge of the court.2: You call getMargin methods on the ball object, and the court can tell whether they are greater than its bounds.In both cases you would call a bounceHorizontally or bounceVertically method on the ball object.
I am not certain, but I think option 2 is more elegant. There are bound to be more such options.
If you make the court class extend a GUI class (e.g.
JPanel), it has getWidth and similar methods, which will allow for any size of court.
There is an alternative to Thread#sleep: a
Swing Timer.