CSE115.BouncyShapes
Class Square

java.lang.Object
  extended byNGP.Graphics.Shape
      extended byNGP.Graphics.RectangularShape
          extended byNGP.Graphics.FilledRectangularShape
              extended byNGP.Graphics.FilledRectangle
                  extended byCSE115.BouncyShapes.Square
All Implemented Interfaces:
Colorable, EventListener, Graphic, Locatable, MouseListener, MouseMotionListener, Reactor, Rotatable, Shape, Sizeable

public class Square
extends FilledRectangle
implements Shape

A square that moves when told to. Must be used with either cs015.SP.Frame or cs015.SP.Applet (or their subclasses). Created: Sun Feb 10 15:00:55 2002

Author:
Phil Ventura, Carl Alphonce Modified to from FilledEllipse to FilledSquare.

Field Summary
 
Fields inherited from class NGP.Graphics.Shape
_awtShape, _dpanel
 
Fields inherited from interface NGP.Colorable
DEFAULT_GRAY
 
Constructor Summary
Square()
          Creates a new Square instance.
 
Method Summary
 int getDx()
          Get the change in x.
 int getDy()
          Get the change in y.
 void setAcceleration(Vector dV)
          Sets the acceleration (change in velocity) of the square using a vector.
 void setFrameDelay(int milliseconds)
          Sets the delay in milliseconds between calls to move().
 void setSize(int newDiameter)
          Set the diameter.
 void setVelocity(int dx, int dy)
          Sets the velocity, in the x and y directions of the square.
 void update()
          Update the position of the square based on the velocity, if the square hits a wall, reverses velocity in the appropriate direction.
 
Methods inherited from class NGP.Graphics.FilledRectangularShape
actualPaint
 
Methods inherited from class NGP.Graphics.RectangularShape
getDimension, getLocation, setCenterLocation, setDimension, setLocation, unwrap, wrap
 
Methods inherited from class NGP.Graphics.Shape
contains, drag, getBounds, getCenterLocation, getColor, getDrawingPanel, getRotation, hide, intersects, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, paint, react, setColor, setDrawingPanel, setRotation, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface NGP.Graphic
contains, getBounds, getCenterLocation, getDrawingPanel, hide, intersects, paint, setDrawingPanel, show
 
Methods inherited from interface NGP.Reactor
react
 
Methods inherited from interface java.awt.event.MouseListener
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased
 
Methods inherited from interface java.awt.event.MouseMotionListener
mouseDragged, mouseMoved
 
Methods inherited from interface NGP.Rotatable
getRotation, setRotation
 
Methods inherited from interface NGP.Locatable
getLocation, setLocation
 
Methods inherited from interface NGP.Sizeable
getDimension, setDimension
 
Methods inherited from interface NGP.Colorable
getColor, setColor
 

Constructor Detail

Square

public Square()
Creates a new Square instance.

Method Detail

update

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

Specified by:
update in interface Shape

setAcceleration

public void setAcceleration(Vector dV)
Sets the acceleration (change in velocity) of the square using a vector.

Specified by:
setAcceleration in interface Shape
Parameters:
dV - the acceleration (change in velocity) vector

setVelocity

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

Parameters:
dx - the new change in x value.
dy - the new change in y value.

getDx

public int getDx()
Get the change in x.

Returns:
the change in x.

getDy

public int getDy()
Get the change in y.

Returns:
the change in y.

setSize

public void setSize(int newDiameter)
Set the diameter.

Parameters:
newDiameter - the new diameter.

setFrameDelay

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

Parameters:
milliseconds - the delay in milliseconds.