previous
contents
next

Fixing the paint method

  public void paint(Graphics g) {
     // Erase previous ball
     g.setColor(Color.white);
     g.fillRect(oldX, oldY, model.BALL_SIZE, model.BALL_SIZE);
     // Draw new ball and remember its position
     g.setColor(Color.red);
     g.fillOval(model.xPosition, model.yPosition,
                 model.BALL_SIZE, model.BALL_SIZE);
     oldX = model.xPosition;
     oldY = model.yPosition;
  }