Class BouncingBall

  • java.lang.Object
    • BouncingBall

  • public class BouncingBall
    extends java.lang.Object
    Class BouncingBall – a graphical ball that observes the effect of gravity. The ball has the ability to move. Details of movement are determined by the ball itself. It will fall downwards, accelerating with time due to the effect of gravity, and bounce upward again when hitting the ground. This movement can be initiated by repeated calls to the “move” method.
    Version:
    2016.02.29
    Author:
    Michael Kölling (mik), David J. Barnes, Bruce Quig

    • Constructor Summary

      Constructors
      Constructor and Description
      BouncingBall(int xPos, int yPos, int ballDiameter, java.awt.Color ballColor, int groundPos, Canvas drawingCanvas)

      Constructor for objects of class BouncingBall

    • Method Summary

      All MethodsInstance MethodsConcrete Methods
      Modifier and Type Method and Description
      void draw()

      Draw this ball at its current position onto the canvas.
      void erase()

      Erase this ball at its current position.
      int getXPosition()

      return the horizontal position of this ball
      int getYPosition()

      return the vertical position of this ball
      void move()

      Move this ball according to its position and speed and redraw.

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


    • Constructor Detail

      • BouncingBall

        public BouncingBall(int xPos,
                            int yPos,
                            int ballDiameter,
                            java.awt.Color ballColor,
                            int groundPos,
                            Canvas drawingCanvas)
        Constructor for objects of class BouncingBall
        Parameters:
        xPos – the horizontal coordinate of the ball
        yPos – the vertical coordinate of the ball
        ballDiameter – the diameter (in pixels) of the ball
        ballColor – the color of the ball
        groundPos – the position of the ground (where the wall will bounce)
        drawingCanvas – the canvas to draw this ball on