|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjturtle.JTurtle
public class JTurtle
This class is a simple SLogo turtle model for illustrating rudimentary MVC for turtles and simple Graphics2D concepts
Constructor Summary | |
---|---|
JTurtle()
Create a turtle using the default (triangle) image. |
|
JTurtle(java.awt.Image img)
|
Method Summary | |
---|---|
void |
addTurtleListener(TurtleListener listener)
Add a listener. |
void |
draw(java.awt.Graphics g)
Draw the turtle, pass in a Graphics2D object. |
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.geom.Point2D |
getPoint()
Returns the turtle's point (should be centroid) |
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 |
setHeading(double radians)
Set heading in radians, notify listeners. |
void |
setHeading(int degrees)
Set heading in degrees, notify listeners. |
void |
setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JTurtle()
public JTurtle(java.awt.Image img)
Method Detail |
---|
public java.awt.Rectangle getBounds(java.awt.Rectangle r)
Component.getBounds()
public void reset()
public void draw(java.awt.Graphics g)
g
- is the graphics context in which Turtle is drawnpublic void move(int steps)
steps
- is the number of steps movedpublic void setHeading(int degrees)
degrees
- will be Turtle's new headingpublic void setHeading(double radians)
radians
- Turtle's new headingpublic double getHeading()
public java.awt.geom.Point2D getPoint()
public void notifyListeners()
public void addTurtleListener(TurtleListener listener)
listener
- is the listener addedpublic void setPoint(java.awt.geom.Point2D p)
p
- is the new center point
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |