I'm currently going through Eric Robert's Art and Science of Java, which uses the ACM Java libraries. One of the exercises has the student build a clone of Breakout. I'm having issues with the animation of objects, so please have a look at this code and if possible tell me why the ball isn't moving.
This is code sample I wrote to isolate the behavior that's giving me troubles, but after spending the entire evening on it, I thought I better ask for help since I wasn't making any progress at all. What the code is supposed to achieve is merely to move the object. (Note: this is NOT a homework problem.)
I set up the canvas with the ball in setup(), and intend to make the ball move in play() but nothing happens.
The code has also been pasted to: http://pastebin.com/vy3rMrZw
package codeSamples_II;
import acm.program.*;
import acm.graphics.*;
public class PlayBall extends GraphicsProgram {
private static final int DELAY = 50;
private GOval ball;
private static final int BALL_RADIUS = 10;
public void run() {
setup();
play();
}
private void setup() {
GOval ball = new GOval(0,0, BALL_RADIUS*2, BALL_RADIUS*2);
ball.setFilled(true);
add(ball);
}
public void play() {
while (ball.getY() < 200) {
ball.move(5, 5);
pause(DELAY);
}
}
}
Thanks a lot!