Hi

I am trying to solve a programming exercise which is in a book that I am reading on Java. Bouncing a ball around a canvass.

Attaching the code here. Please tell where I have gone wrong. Also is there any way to get the x and y numbers without using the "get" function.

Thank you

public class BouncingBall extends GraphicsProgram { public void run() { double centeredx = (getWidth()/2); double centeredy = (getHeight()/2); GOval ball = new GOval(centeredx,centeredy,BALL_SIZE,BALL_SIZE); ball.setFilled(true); add(ball); double dx = 1; double dy = 1; while (true){ ball.move(dx,dy); pause(PAUSE_TIME); double x = ball.getX(); double y = ball.getY(); if (x >= getWidth() - BALL_SIZE){ dx = - 1; if (y >= getHeight() - BALL_SIZE){ dy = - 1; if (x == 0){ dx = -1; if (y == 0){ dy = -1; } } } } } } /* Private constant*/ private static final int BALL_SIZE = 40; private static final int PAUSE_TIME = 50;