simulation_Lab06Version
Class SimulationRunnable

java.lang.Object
  extended by simulation_Lab06Version.SimulationRunnable
All Implemented Interfaces:
Runnable

public class SimulationRunnable
extends Object
implements Runnable

This class encapsulates an animation and some basic services to change the frame rate. The frames that are shown in the animation are specified by a component encapsulated by an ActionListener (and which must be provided to the constructor of this class). This app is provided for teaching purposes.

Author:
mb

Constructor Summary
SimulationRunnable(ActionListener frameDrawer)
          Creates a runnable.
 
Method Summary
 int getFrameRate()
          Accessor for this animation's frame rate.
 void run()
          Causes this runnable to launch.
 void run(int frameRate)
          Causes this runnable to launch.
 boolean setFrameRate(int targetFrameRate)
          Update this animation's frame rate to the passed value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimulationRunnable

public SimulationRunnable(ActionListener frameDrawer)
Creates a runnable. The default frame rate is 30 frames per second.

Method Detail

getFrameRate

public int getFrameRate()
Accessor for this animation's frame rate.

Returns:
as described above

setFrameRate

public boolean setFrameRate(int targetFrameRate)
Update this animation's frame rate to the passed value. If the passed value is less than 1 frame per second, or if this animation is already running, then this animation's frame rate will not be updated.

Parameters:
targetFrameRate - the target frame rate
Returns:
true is this animation's frame rate was successfully updated to the target framerate, false otherwise

run

public void run(int frameRate)
Causes this runnable to launch. The frame rate will be as specified by the parameter.

Parameters:
frameRate -

run

public void run()
Causes this runnable to launch. The frame rate will be the default value for this runnable (1 frame per second).

Specified by:
run in interface Runnable