gui.frame
Class JTurtle

java.lang.Object
  |
  +--gui.frame.JTurtle

public class JTurtle
extends java.lang.Object

This class is a simple MoboLogo/Slogo turtle model for illustrating rudimentary MVC for turtles and simple Graphics2D concepts


Method Summary
 void addTurtleListener(TurtleListener listener)
          Add a listener.
 void clean()
           
 void draw(java.awt.Graphics context, javax.swing.JPanel contextField)
          Draw the turtle, pass in a Graphics2D object.
 java.awt.Color getBackground()
           
 java.awt.Rectangle getBounds(java.awt.Rectangle r)
          Mirrors the functionality of JComponent/Component.
 double getHeading()
          Returns the naive view of heading, 0 degrees = north
 java.awt.Image getImage()
           
static JTurtle getInstance()
           
 java.awt.geom.Point2D getPoint()
          Returns the turtle's point (should be centroid)
 boolean isVisible()
           
 void move(int steps)
          Moves the turtle forward.
 void notifyListeners()
          Ask all registered listeners to process this turtle
 void reset()
          Reposition turtle at the origin, facing north.
 void setBackground(java.awt.Color c)
           
 void setHeading(double radians)
          Set heading in radians, notify listeners.
 void setHeading(int degrees)
          Set heading in degrees, notify listeners.
 void setImage(java.awt.Image im)
          sets the turtle image depending on what the user chooses
 void setPoint(java.awt.geom.Point2D p)
          Sets the turtles point, notifies listeners.
 void setVisbility(boolean b)
           
protected  double trueHeading()
          Return the real/true heading of the turtle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static JTurtle getInstance()
Returns:
the single instance of this object

getBounds

public java.awt.Rectangle getBounds(java.awt.Rectangle r)
Mirrors the functionality of JComponent/Component. The current turtle isn't a Component, but it sort of acts like one (it's drawable).

See Also:
Component.getBounds()

reset

public void reset()
Reposition turtle at the origin, facing north.


clean

public void clean()

setImage

public void setImage(java.awt.Image im)
sets the turtle image depending on what the user chooses

Parameters:
im - image to which to set the turtle

getImage

public java.awt.Image getImage()
Returns:
current Image representing the Turtle on the canvas

draw

public void draw(java.awt.Graphics context,
                 javax.swing.JPanel contextField)
Draw the turtle, pass in a Graphics2D object.


trueHeading

protected double trueHeading()
Return the real/true heading of the turtle. A Turtle's "heading" is what naive users would expect, i.e., 0 degrees == north, 90 degrees = east, -90 degrees = west. The trueheading translates to what Graphics/geometry expects

Returns:
the true heading in radians

move

public void move(int steps)
Moves the turtle forward.

Parameters:
steps - is the number of steps moved

setHeading

public void setHeading(int degrees)
Set heading in degrees, notify listeners.

Parameters:
degrees - will be Turtle's new heading

setHeading

public void setHeading(double radians)
Set heading in radians, notify listeners.


getHeading

public double getHeading()
Returns the naive view of heading, 0 degrees = north

Returns:
the heading

getPoint

public java.awt.geom.Point2D getPoint()
Returns the turtle's point (should be centroid)


notifyListeners

public void notifyListeners()
Ask all registered listeners to process this turtle


addTurtleListener

public void addTurtleListener(TurtleListener listener)
Add a listener.

Parameters:
listener - is the listener added

setPoint

public void setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners.

Parameters:
p - is the new center point

isVisible

public boolean isVisible()

setVisbility

public void setVisbility(boolean b)

setBackground

public void setBackground(java.awt.Color c)

getBackground

public java.awt.Color getBackground()