Class Stepper

java.lang.Object
  extended byjava.lang.ThreadGroup
      extended byStepper

public class Stepper
extends java.lang.ThreadGroup

The Stepper class can be attached to the turtle Canvas to control how fast things happen. It can move the turtles one step at a time, or set steps to happen continuously with a specified delay for each. There is only one Stepper instantiated; it can be retrieved with getStepper(). The Stepper manages a single "run" through the commands in Controller.run(). The run can be paused, stopped, restarted, or advanced a step at a time by various Stepper methods. There is only one run active a any time; any old runs are terminated when a new run begins.

Version:
6/3/05
Author:
Russell Zahniser

Field Summary
 
Fields inherited from class java.lang.ThreadGroup
 
Method Summary
 void checkRun()
          Check to make sure that you aren't part of a dead run.
 void didStep()
          End a step of the run.
 void endRun()
          Stop the current run, without waiting for it to finish.
 Canvas getCanvas()
          Return the canvas that this Stepper is attached to.
static Stepper getStepper()
          Return the Stepper.
 boolean isStopped()
          Check whether the stepper is stopped.
 void newRun()
          Make a new run.
 void pause()
          Pause the current run.
 void restart()
          Restart the current run, if it was paused.
 void setScale(double setting)
          The applet should call this when it wants to change the scale of the canvas.
 void setSpeed(int speed)
          Set the speed for the run.
 void step()
          Move the current run forward one step.
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

checkRun

public void checkRun()
Check to make sure that you aren't part of a dead run. A Turtle should check this before it does anything so that it will not accidentally draw onto the new Canvas.


didStep

public void didStep()
End a step of the run. A turtle should access this through Turtle.done(). This will pause the run for the appropriate amount of time, or have it wait for the run to start up again.


endRun

public void endRun()
Stop the current run, without waiting for it to finish. This also clears the canvas.


getCanvas

public Canvas getCanvas()
Return the canvas that this Stepper is attached to.

Returns:
the Canvas.

getStepper

public static Stepper getStepper()
Return the Stepper.

Returns:
the Stepper

isStopped

public boolean isStopped()
Check whether the stepper is stopped.

Returns:
true if the current run is paused.

newRun

public void newRun()
Make a new run. Any old run is ended.


pause

public void pause()
Pause the current run. It can be restarted with restart().


restart

public void restart()
Restart the current run, if it was paused.


setScale

public void setScale(double setting)
The applet should call this when it wants to change the scale of the canvas. This affects how big things are drawn, not what the turtles' actual coordinates are.

Parameters:
setting - How big to draw, from 0 (tiny) to 4 (HUGE)

setSpeed

public void setSpeed(int speed)
Set the speed for the run.

Parameters:
speed - Length of pause per step, from 0 (very fast) to 6 (slow)

step

public void step()
Move the current run forward one step. It will then be paused.