de.nidanet.dev.fun.winter.snow
Class Flake

java.lang.Object
  extended by de.nidanet.dev.fun.winter.snow.Flake
All Implemented Interfaces:
Runnable

public class Flake
extends Object
implements Runnable

Objects of this class move over the screen like snow flakes! Each runs as a single thread until it is placed at "a point of no return". See run() method for more information.

Since:
2009-12-19
Version:
1.0
Author:
Nico Danneberg (mail@danneberg.de)

Field Summary
private  boolean[][] FixPoints
          An array with all fixed points at the screen.
private  Graphics Graph
          A reference to the screen.
private  Snow Parent
          A reference to the displaying object.
static long serialVersionUID
          Unique Id of this class.
private  long tts
          Time-To-Sleep between the single falling steps.
private  int x
          Current x-position of this flake.
private  int y
          Current y-position of this flake.
 
Constructor Summary
Flake(Snow p, int x, long t)
          Creates and initializes a new flake at position (x;0).
 
Method Summary
 void addFixPoint(int a, int b)
          Adds a new fixed point to the local array.
 int getX()
          Reads the x-position.
 int getY()
          Reads the y-position.
 void run()
          Let the flake move over the screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
Unique Id of this class.

See Also:
Constant Field Values

Parent

private Snow Parent
A reference to the displaying object.


Graph

private Graphics Graph
A reference to the screen.


FixPoints

private boolean[][] FixPoints
An array with all fixed points at the screen.


x

private int x
Current x-position of this flake.


y

private int y
Current y-position of this flake.


tts

private long tts
Time-To-Sleep between the single falling steps. See run().

Constructor Detail

Flake

public Flake(Snow p,
             int x,
             long t)
Creates and initializes a new flake at position (x;0). This does not start any displaying or falling process!

Parameters:
p - the parent object's reference
x - the x-position
t - the Time-To-Sleep
Method Detail

run

public void run()
Let the flake move over the screen. Therefore the flakes moves in a loop one single pixel down per step. If there is a fix point at the new y-position a left or right move is chosen randomly. If both directions are also used by fixed points the current point becomes an additional fixed point itself and the flake stops falling.

Specified by:
run in interface Runnable

addFixPoint

public void addFixPoint(int a,
                        int b)
Adds a new fixed point to the local array.

Parameters:
a - the x-position of the new fixed point
b - the y-position of the new fixed point

getX

public int getX()
Reads the x-position.

Returns:
the value of x

getY

public int getY()
Reads the y-position.

Returns:
the value of y