Ball World Problem Set Javadocs

ballworld
Class BallRenderer

java.lang.Object
  extended byballworld.BallRenderer

public class BallRenderer
extends java.lang.Object

Holds and animates one ball which can be rendered upon requested. Also provides methods for transforming between world corrdinates (cartesian with 0,0 at center) and GUI coordinates (0,0 at upper left with inverted vertical scale as is the norm in Java GUI components)

Author:
Patrick G. Heck, gus.heck@olin.edu

Constructor Summary
BallRenderer(Ball b, BallWorld w)
          Creates a new instance of BallRenderer
 
Method Summary
 boolean containsPoint(java.awt.Point p)
          Check whether or not the given point resides within the radius of the ball.
 double distanceTo(java.awt.Point p)
          Find the distance from our ball to the given point.
 void drawBall(java.awt.Graphics2D G)
          Draw the ball on the given graphics context.
 Ball getBall()
          Get the ball held by this renderer.
 void setSelected(boolean state)
          Set the selection status for this ball;
 void stop()
          Stop the Animator thread.
static java.awt.Point transformGUI2World(java.awt.Point p, BallWorld w)
          Convert a point from GUI coordinates to world coordinates.
static java.awt.Point transformWorld2GUI(java.awt.Point p, BallWorld w)
          Convert a point from world coordinates to GUI coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BallRenderer

public BallRenderer(Ball b,
                    BallWorld w)
Creates a new instance of BallRenderer

Parameters:
b - The Ball we are responsible for rendering
w - The BallWorld that
Method Detail

drawBall

public void drawBall(java.awt.Graphics2D G)
Draw the ball on the given graphics context.

Parameters:
G - A graphics context for drawing

getBall

public Ball getBall()
Get the ball held by this renderer.

Returns:
the ball contained by this renderer.

setSelected

public void setSelected(boolean state)
Set the selection status for this ball;

Parameters:
state - the state to set (selected or not)

containsPoint

public boolean containsPoint(java.awt.Point p)
Check whether or not the given point resides within the radius of the ball.

Parameters:
p - The point to check
Returns:
true if our ball contains this point, false otherwise.

distanceTo

public double distanceTo(java.awt.Point p)
Find the distance from our ball to the given point.

Parameters:
p - The point to measure the distance to
Returns:
The distance between the given coordinate and our ball

stop

public void stop()
Stop the Animator thread.


transformWorld2GUI

public static java.awt.Point transformWorld2GUI(java.awt.Point p,
                                                BallWorld w)
Convert a point from world coordinates to GUI coordinates. World coordinates are 0,0 at the center of the window with Y increasing in the up direction (standard Cartesian coordinates). GUI Coordinates are 0,0 at the upper left with Y increasing downwards

Parameters:
w - The world we are converting from
p - A point in world coordinates
Returns:
A point in GUI coordinates

transformGUI2World

public static java.awt.Point transformGUI2World(java.awt.Point p,
                                                BallWorld w)
Convert a point from GUI coordinates to world coordinates. World coordinates 0,0 at the center of the window with Y increasing in the up direction (standard Cartesian coordinates). GUI Coordinates are 0,0 at the upper left with Y increasing downwards

Parameters:
w - The world we are converting to
p - A point in GUI coordinates
Returns:
A point in world coordinates

Ball World Problem Set Javadocs