Class Bouncing Ball
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 ballint
getYPosition()
return the vertical position of this ballvoid
move()
Move this ball according to its position and speed and redraw.
-
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 ballyPos
– the vertical coordinate of the ballballDiameter
– the diameter (in pixels) of the ballballColor
– the color of the ballgroundPos
– the position of the ground (where the wall will bounce)drawingCanvas
– the canvas to draw this ball on
-
Method Detail
-
draw[Show source in BlueJ]
public void draw()
Draw this ball at its current position onto the canvas.
-
erase[Show source in BlueJ]
public void erase()
Erase this ball at its current position.
-
getXPosition[Show source in BlueJ]
public int getXPosition()
return the horizontal position of this ball
-
getYPosition[Show source in BlueJ]
public int getYPosition()
return the vertical position of this ball
-
move[Show source in BlueJ]
public void move()
Move this ball according to its position and speed and redraw.
-