Class Ball

java.lang.Object
  extended byBall
All Implemented Interfaces:
SimThing

public class Ball
extends Object
implements SimThing

A small ball object that wanders randomly around a bounded area. CSE143 lecture demo Au01, Sp03, Sp04

Version:
10/18/01, 4/16/03, 4/12/04
Author:
Hal Perkins

Constructor Summary
Ball(int x, int y, int dx, int dy, Color c, int diameter, SimModel model)
          Construct a new Ball with the given coordinates, initial direction, and model.
 
Method Summary
 void action()
          Perform an appropriate action on each cycle of the simulation, in this case advancing by dx,dy and reversing either direction if we hit an edge of the simulation.
 void paintComponent(Graphics g)
          Display this ball on the given graphics context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ball

public Ball(int x,
            int y,
            int dx,
            int dy,
            Color c,
            int diameter,
            SimModel model)
Construct a new Ball with the given coordinates, initial direction, and model.

Parameters:
x - initial x coordinate of center of the ball
y - initial y coordinate of center of the ball
dx - initial change in x value on each simulation cycle
dy - initial change in y value on each simulation cycle
c - color of the ball
diameter - diameter of the ball
model - the model that this Ball is a part of
Method Detail

action

public void action()
Perform an appropriate action on each cycle of the simulation, in this case advancing by dx,dy and reversing either direction if we hit an edge of the simulation.

Specified by:
action in interface SimThing

paintComponent

public void paintComponent(Graphics g)
Display this ball on the given graphics context

Specified by:
paintComponent in interface SimThing
Parameters:
g - the graphics context where this ball should be drawn