|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.otherwise.jurtle.Turtle
The Turtle class is an abstract class you extend to give your turtle its
specific behavior. You do this by implementing the runTurtle()
method, and in this method call other various Turtle methods to have it move
and draw on the screen. This runTurtle()
method is automatically
called by Jurtle when you run the Turtle.
If the Turtle implements a public static main(String[] args),
method, it will be called first instead of runTurtle()
. The main
method is then responsible for instantiating the turtle (or turtles) and calling
its start()
method. The call to start()
will then
result in runTurtle
being called.
Field Summary | |
static int |
NO_PAUSE
Constant that can be passed to pause() or
setAutoUpdatePause() to indicate there should be no actual
pause. |
Constructor Summary | |
Turtle()
Basic Turtle constructor. |
|
Turtle(java.awt.Color penColor,
int penWidth,
double heading,
double x,
double y)
Turtle constructor that allows you to specify the initial penColor, penWidth, heading and position. |
Method Summary | |
void |
backward(double distance)
Move the turtle backward the specified distance. |
void |
center()
Center the turtle in the display pane. |
void |
clearDisplay()
Clears the display, leaving the turtle where it is. |
void |
forward(double distance)
Move the turtle forward the specified distance. |
boolean |
getAutoUpdate()
Gets the current value of the autoUpdate flag. |
long |
getAutoUpdatePause()
Gets the autoUpdate pause value. |
javax.swing.JPanel |
getDisplay()
Returns the JPanel used for the Turtle's display area. |
java.awt.Color |
getDisplayColor()
Returns the display's background color. |
java.awt.Container |
getDisplayContainer()
Returns the Container that contains the Turtle's display area. |
java.awt.Dimension |
getDisplaySize()
Return the size of the turtle's display pane. |
java.awt.Graphics |
getGraphics()
Return the turtle's graphics context. |
double |
getHeading()
Return the turtle's heading. |
java.awt.Color |
getPenColor()
|
int |
getPenWidth()
Returns the turtle's penWidth. |
java.awt.Color |
getPixelColor(int x,
int y)
Returns the color of the pixel at the specified point in the display's coordinate system (0,0 is at the upper left of the display). |
java.awt.Point |
getPosition()
Return the current position of the turtle. |
java.util.Enumeration |
getTurtles()
Returns an Enumeration of all the current turtles. |
void |
hideTurtle()
Hide the turtle so it will not be seen while drawing. |
void |
home()
Return the turtle to its default (home) state. |
boolean |
isPenDown()
Returns whether the pen is currently down. |
boolean |
isRunning()
Gets the turtle's running status. |
boolean |
isVisible()
Determine if the turtle is visible. |
void |
left(double degrees)
Rotate the turtle to the left (counterclockwise). |
void |
paintTurtle(java.awt.Graphics g)
Called to have the turtle paint itself. |
void |
pause(long pauseMillis)
Pauses the turtle's execution for pauseMillis milliseconds. |
void |
penDown()
Put the turtle's pen back down so it will draw when moving. |
void |
penErase()
Change the pen to an eraser. |
void |
penPaint()
Return the drawing version of the pen after erasing. |
void |
penUp()
Lift the turtle's pen so it doesn't draw when moving |
void |
right(double degrees)
Rotate the turtle to the right (clockwise). |
void |
run()
Called by start() to begin running the turtle's thread. |
abstract void |
runTurtle()
Called to execute the turtle code in a separate thread. |
void |
setAutoUpdate(boolean autoUpdate)
Sets a flag indicating whether to automatically update the display after each turtle command that affects it. |
void |
setAutoUpdatePause(long pauseMillis)
Sets the number of milliseconds the system pauses after performing an automatic update. |
void |
setDisplayColor(java.awt.Color color)
Set the display's background color. |
void |
setHeading(double heading)
Set the direction the turtle is pointing in. |
void |
setPenColor(java.awt.Color color)
Set the pen color for the trail the turtle leaves. |
void |
setPenWidth(int width)
Set the pen width for the trail the turtle leaves. |
void |
setPixelColor(int x,
int y,
java.awt.Color color)
Sets the color of the pixel at the specified point in the display's coordinate system (0,0 is at the upper left of the display). |
void |
setPosition(double newX,
double newY)
Move the turtle to the specified coordinates. |
void |
setPositionX(double newX)
Move the turtle to the new x coordinate leaving the y coordinate unchanged. |
void |
setPositionY(double newY)
Move the turtle to the new y coordinate leaving the x coordinate unchanged. |
void |
showTurtle()
Shows the turtle, making it visible. |
void |
start()
Called to start running the turtle in its own thread of execution. |
void |
stopTurtle()
Stops the turtle's execution. |
void |
turtleStopped()
Called by Jurtle when the turtle has been stopped. |
void |
updateDisplay()
Update the display with any turtle drawing. |
void |
waitForStop()
Causes the turtle's thread to sleep and wait for either stopTurtle() to be called or Stop command to be invoked from
Jurtle's GUI. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NO_PAUSE
pause()
or
setAutoUpdatePause()
to indicate there should be no actual
pause.
Constructor Detail |
public Turtle()
public Turtle(java.awt.Color penColor, int penWidth, double heading, double x, double y)
Method Detail |
public void backward(double distance)
distance
- the distance to move the turtle.public void center()
public void clearDisplay()
public void forward(double distance)
distance
- the distance to move the turtle.public boolean getAutoUpdate()
setAutoUpdate(boolean)
public long getAutoUpdatePause()
setAutoUpdate(boolean)
public javax.swing.JPanel getDisplay()
public java.awt.Container getDisplayContainer()
public java.awt.Color getDisplayColor()
setDisplayColor(java.awt.Color)
public java.awt.Dimension getDisplaySize()
public java.awt.Graphics getGraphics()
Graphic g = getGraphics();
synchronized( g )
{
    g.fillRect(100, 100, 20, 20);
}
public double getHeading()
public java.awt.Color getPenColor()
public boolean isPenDown()
public int getPenWidth()
public java.awt.Color getPixelColor(int x, int y)
public java.awt.Point getPosition()
public java.util.Enumeration getTurtles()
public void hideTurtle()
public void home()
public boolean isRunning()
public boolean isVisible()
public void left(double degrees)
degrees
- the number of degrees to rotate the turtle.public void paintTurtle(java.awt.Graphics g)
g
- the Graphics object to use for drawing.public void pause(long pauseMillis)
pauseMillis
milliseconds. If
pauseMillis
is 0 or less, no pause will happen.
public void penDown()
public void penErase()
public void penPaint()
public void penUp()
public void right(double degrees)
degrees
- the number of degrees to rotate the turtle.public void run()
run
in interface java.lang.Runnable
public abstract void runTurtle()
public void setAutoUpdate(boolean autoUpdate)
autoUpdate
- a boolean flag indicating whether to turn automatic
display on or off.public void setAutoUpdatePause(long pauseMillis)
setAutoUpdate(true)
has been called to turn on automatic
updating, then after each display update, the turtle will pause for
pauseMillis
milliseconds. This is useful to see the
individual drawing operations.
pauseMillis
- number of milliseconds to automatically pause after
drawing commands.public void setDisplayColor(java.awt.Color color)
public void setHeading(double heading)
heading
- the direction to point the turtle. 0 degrees is North and 90
is East.public void setPenColor(java.awt.Color color)
color
- the color to set the pen to.public void setPenWidth(int width)
width
- the width to set the pen to.public void setPixelColor(int x, int y, java.awt.Color color)
x
- x-coordinate of pixely
- y-coordinate of pixelcolor
- color to set pixel at the specified pointpublic void setPosition(double newX, double newY)
newX
- new x coordinatenewY
- new y coordinatepublic void setPositionX(double newX)
newX
- new x coordinatepublic void setPositionY(double newY)
newY
- new y coordinatepublic void showTurtle()
public void start()
public void stopTurtle()
runTurtle()
method exit. However if you called
waitForStop()
at the end of the runTurtle()
method,
stopTurtle
may be call to end execution.
public void turtleStopped()
public void updateDisplay()
public void waitForStop()
stopTurtle()
to be called or Stop command to be invoked from
Jurtle's GUI. This method should be called if your code creates any GUI
elements and then would normally exit. Call this method after creating the
GUI and it will keep the main turtle thread alive.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |