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

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by de.nidanet.dev.fun.winter.snow.Snow
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Runnable, Accessible

public class Snow
extends Canvas
implements Runnable

An object of this class represents the screen for the falling flakes. It runs as an single thread, too and produces every 5ms a new flake at a random x-position.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  boolean active
          While the object is active, new flakes will occure.
private  ThreadGroup AllFlakes
          A group for all flakes is needed for calling common thread methods.
private  boolean[][] FixPoints
          An array for all fixed points at this screen.
private  long FlakeCounter
          A global flake's counter to create unique IDs.
private  Vector<Flake> Flakes
          The storage of all active flakes.
private  Color FontColor
          The color of the text.
private  String[] Messages
          The 3 lines of message that will be displayed.
private  Image Screen
          The screen all flakes are painting at.
static long serialVersionUID
          Unique Id of this class.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Snow(String msg1, String msg2, String msg3, Color c)
          Creates the new screen and initializes the text and color.
 
Method Summary
 boolean[][] getFixPoints()
          Reads reads the local array of all fixed points.
private  void initFixPoints()
          Initializes FixPoints by running through a raster of the complete screen and storing all point that are not of RGB( 0, 0, 0 ).
 void paint(Graphics g)
          Since the screen inherits from Canvas it has to know how to paint itself.
 void removeFlake(Flake f)
          When a flake reached a fixed point, it notifies this screen about this.
 void run()
          While the screen is active it created new flakes every 5ms at a random x-position.
 void stop()
          It stops the screen by setting active to false and interrupts all flakes.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
Unique Id of this class.

See Also:
Constant Field Values

active

private boolean active
While the object is active, new flakes will occure.


Flakes

private Vector<Flake> Flakes
The storage of all active flakes.


AllFlakes

private ThreadGroup AllFlakes
A group for all flakes is needed for calling common thread methods.


FlakeCounter

private long FlakeCounter
A global flake's counter to create unique IDs.


FixPoints

private boolean[][] FixPoints
An array for all fixed points at this screen.


Screen

private Image Screen
The screen all flakes are painting at.


Messages

private String[] Messages
The 3 lines of message that will be displayed.


FontColor

private Color FontColor
The color of the text.

Constructor Detail

Snow

public Snow(String msg1,
            String msg2,
            String msg3,
            Color c)
Creates the new screen and initializes the text and color. active is false right now.

Parameters:
msg1 - the 1st line of the text
msg2 - the 2nd line of the text
msg3 - the 3rd line of the text
c - the Messages color
Method Detail

run

public void run()
While the screen is active it created new flakes every 5ms at a random x-position.

Specified by:
run in interface Runnable

stop

public void stop()
It stops the screen by setting active to false and interrupts all flakes.


paint

public void paint(Graphics g)
Since the screen inherits from Canvas it has to know how to paint itself. Here the text is written and the FixPoints are initialized.

Overrides:
paint in class Canvas
Parameters:
g - the graphics object

removeFlake

public void removeFlake(Flake f)
When a flake reached a fixed point, it notifies this screen about this. The flake will be removed from AllFlakes, and the new fixed point is stored locally and is given to every falling flake calling method Flake.addFixPoint(int, int).

Parameters:
f - the flake to remove
See Also:
Flake.addFixPoint(int, int)

getFixPoints

public boolean[][] getFixPoints()
Reads reads the local array of all fixed points.

Returns:
FixPoints

initFixPoints

private void initFixPoints()
Initializes FixPoints by running through a raster of the complete screen and storing all point that are not of RGB( 0, 0, 0 ).