CSE115.BallWorld
Class MovingBodyAdapter

java.lang.Object
  |
  +--CSE115.BallWorld.MovingBodyAdapter
All Implemented Interfaces:
Colorable, EventListener, Graphic, Locatable, MouseListener, MouseMotionListener, MovingBody, Reactor, Rotatable, Shape, Sizeable
Direct Known Subclasses:
Ball, BouncingPicture

public abstract class MovingBodyAdapter
extends Object
implements MovingBody

Normal users can ignore this class. A class that implements many of the methods of MovingBody by delegating the work to Shape objects. This class is only made available for those wishing to create new type of MovingBody classes. Created: Sat Jan 31 14:56:17 2004

Author:
Phil Ventura

Field Summary
 
Fields inherited from interface NGP.Colorable
DEFAULT_GRAY
 
Constructor Summary
MovingBodyAdapter(Shape delegate)
          Creates a new MovingBodyAdapter instance.
 
Method Summary
 boolean contains(Point param1)
          Delegated to the shape.
 Rectangle getBounds()
          Delegated to the shape.
 Point getCenterLocation()
          Delegated to the shape.
 Color getColor()
          Delegated to the shape.
 Dimension getDimension()
          Delegated to the shape.
 DrawingPanel getDrawingPanel()
          Delegated to the shape.
 int getDx()
          Get the change in x.
 int getDy()
          Get the change in y.
 Point getLocation()
          Delegated to the shape.
 int getRotation()
          Delegated to the shape.
 void hide()
          Delegated to the shape.
 boolean intersects(Graphic param1)
          Delegated to the shape.
 void mouseClicked(MouseEvent param1)
          Delegated to the shape.
 void mouseDragged(MouseEvent param1)
          Delegated to the shape.
 void mouseEntered(MouseEvent param1)
          Delegated to the shape.
 void mouseExited(MouseEvent param1)
          Delegated to the shape.
 void mouseMoved(MouseEvent param1)
          Delegated to the shape.
 void mousePressed(MouseEvent param1)
          Delegated to the shape.
 void mouseReleased(MouseEvent param1)
          Delegated to the shape.
 void paint(Graphics2D param1)
          Delegated to the shape.
 void react()
           
 void setBackgroundColor(Color color)
          Set the color of the background.
 void setColor(Color param1)
          Delegated to the shape.
 void setDimension(Dimension param1)
          Delegated to the shape.
 void setDrawingPanel(DrawingPanel param1)
          Delegated to the shape.
 void setFrameDelay(int milliseconds)
          Sets the delay in milliseconds between calls to move().
 void setLocation(Point param1)
          Delegated to the shape.
 void setRotation(int param1)
          Delegated to the shape.
 void setVelocity(int dx, int dy)
          Sets the velocity, in the x and y directions of the ball.
 void show()
          Delegated to the shape.
 void startBouncing()
          Start (global) bouncing behavior.
 void stopBouncing()
          Stop (global) bouncing behavior.
 void update()
          Update the position of the ball based on the velocity, if the ball hits a wall, reverses velocity in the appropriate direction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MovingBodyAdapter

public MovingBodyAdapter(Shape delegate)
Creates a new MovingBodyAdapter instance.

Parameters:
delegate - the shape that does the work.
Method Detail

update

public void update()
Update the position of the ball based on the velocity, if the ball hits a wall, reverses velocity in the appropriate direction.

Specified by:
update in interface MovingBody

setVelocity

public void setVelocity(int dx,
                        int dy)
Sets the velocity, in the x and y directions of the ball.

Specified by:
setVelocity in interface MovingBody
Parameters:
dx - the new change in x value.
dy - the new change in y value.

getDx

public int getDx()
Get the change in x.

Specified by:
getDx in interface MovingBody
Returns:
the change in x.

getDy

public int getDy()
Get the change in y.

Specified by:
getDy in interface MovingBody
Returns:
the change in y.

setFrameDelay

public void setFrameDelay(int milliseconds)
Sets the delay in milliseconds between calls to move().

Parameters:
milliseconds - the delay in milliseconds.

startBouncing

public void startBouncing()
Start (global) bouncing behavior.


stopBouncing

public void stopBouncing()
Stop (global) bouncing behavior.


setBackgroundColor

public void setBackgroundColor(Color color)
Set the color of the background.

Parameters:
color - the new background color.

contains

public boolean contains(Point param1)
Delegated to the shape.

Specified by:
contains in interface Graphic
See Also:
Graphic.contains(Point)

intersects

public boolean intersects(Graphic param1)
Delegated to the shape.

Specified by:
intersects in interface Graphic
See Also:
Graphic.intersects(Graphic)

paint

public void paint(Graphics2D param1)
Delegated to the shape.

Specified by:
paint in interface Graphic
See Also:
Graphic.paint(Graphics2D)

hide

public void hide()
Delegated to the shape.

Specified by:
hide in interface Graphic
See Also:
Graphic.hide()

show

public void show()
Delegated to the shape.

Specified by:
show in interface Graphic
See Also:
Graphic.show()

setDrawingPanel

public void setDrawingPanel(DrawingPanel param1)
Delegated to the shape.

Specified by:
setDrawingPanel in interface Graphic
See Also:
Graphic.setDrawingPanel(DrawingPanel)

getDrawingPanel

public DrawingPanel getDrawingPanel()
Delegated to the shape.

Specified by:
getDrawingPanel in interface Graphic
See Also:
Graphic.getDrawingPanel()

getBounds

public Rectangle getBounds()
Delegated to the shape.

Specified by:
getBounds in interface Graphic
See Also:
Graphic.getBounds()

getCenterLocation

public Point getCenterLocation()
Delegated to the shape.

Specified by:
getCenterLocation in interface Graphic
See Also:
Graphic.getCenterLocation()

setColor

public void setColor(Color param1)
Delegated to the shape.

Specified by:
setColor in interface Colorable
See Also:
Colorable.setColor(Color)

getColor

public Color getColor()
Delegated to the shape.

Specified by:
getColor in interface Colorable
See Also:
Colorable.getColor()

mouseDragged

public void mouseDragged(MouseEvent param1)
Delegated to the shape.

Specified by:
mouseDragged in interface MouseMotionListener
See Also:
MouseMotionListener.mouseDragged(MouseEvent)

mouseMoved

public void mouseMoved(MouseEvent param1)
Delegated to the shape.

Specified by:
mouseMoved in interface MouseMotionListener
See Also:
MouseMotionListener.mouseMoved(MouseEvent)

mouseClicked

public void mouseClicked(MouseEvent param1)
Delegated to the shape.

Specified by:
mouseClicked in interface MouseListener
See Also:
MouseListener.mouseClicked(MouseEvent)

mouseEntered

public void mouseEntered(MouseEvent param1)
Delegated to the shape.

Specified by:
mouseEntered in interface MouseListener
See Also:
MouseListener.mouseEntered(MouseEvent)

mouseExited

public void mouseExited(MouseEvent param1)
Delegated to the shape.

Specified by:
mouseExited in interface MouseListener
See Also:
MouseListener.mouseExited(MouseEvent)

mousePressed

public void mousePressed(MouseEvent param1)
Delegated to the shape.

Specified by:
mousePressed in interface MouseListener
See Also:
MouseListener.mousePressed(MouseEvent)

mouseReleased

public void mouseReleased(MouseEvent param1)
Delegated to the shape.

Specified by:
mouseReleased in interface MouseListener
See Also:
MouseListener.mouseReleased(MouseEvent)

setDimension

public void setDimension(Dimension param1)
Delegated to the shape.

Specified by:
setDimension in interface Sizeable
See Also:
Sizeable.setDimension(Dimension)

getDimension

public Dimension getDimension()
Delegated to the shape.

Specified by:
getDimension in interface Sizeable
See Also:
Sizeable.getDimension()

getLocation

public Point getLocation()
Delegated to the shape.

Specified by:
getLocation in interface Locatable
See Also:
Locatable.getLocation()

setLocation

public void setLocation(Point param1)
Delegated to the shape.

Specified by:
setLocation in interface Locatable
See Also:
Locatable.setLocation(Point)

setRotation

public void setRotation(int param1)
Delegated to the shape.

Specified by:
setRotation in interface Rotatable
See Also:
Rotatable.setRotation(int)

getRotation

public int getRotation()
Delegated to the shape.

Specified by:
getRotation in interface Rotatable
See Also:
Rotatable.getRotation()

react

public void react()
Specified by:
react in interface Reactor
See Also:
Reactor.react()