Game of Life 1.5

org.bitstorm.gameoflife
Class GameOfLife

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byjava.applet.Applet
                  extended byorg.bitstorm.gameoflife.GameOfLife
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, GameOfLifeControlsListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
StandaloneGameOfLife

public class GameOfLife
extends java.applet.Applet
implements java.lang.Runnable, GameOfLifeControlsListener

The Game Of Life Applet. This is the heart of the program. It initializes everything en put it together.

Author:
Edwin Martin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int cellCols
           
protected  int cellRows
           
protected  int cellSize
           
protected  GameOfLifeControls controls
           
protected  CellGridCanvas gameOfLifeCanvas
           
protected  GameOfLifeGrid gameOfLifeGrid
           
protected static java.lang.Thread gameThread
           
protected  int genTime
           
 
Fields inherited from class java.applet.Applet
 
Fields inherited from class java.awt.Panel
 
Fields inherited from class java.awt.Container
 
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
GameOfLife()
           
 
Method Summary
 void alert(java.lang.String s)
          Shows an alert
 java.lang.String getAppletInfo()
           
 int getCellSize()
          Gets cell size.
protected  int getParamInteger(java.lang.String name, int defaultParam)
          Read applet parameter (int) or, when unavailable, get default value.
protected  void getParams()
          Get params (cellSize, cellCols, cellRows, genTime) from applet-tag
 void init()
          Initialize UI.
 boolean isRunning()
          Is the applet running?
 void nextButtonClicked(GameOfLifeControlsEvent e)
          Callback from GameOfLifeControlsListener
 void nextGeneration()
          Go to the next generation.
 void reset()
          Resets applet (after loading new shape)
 void run()
           
 void setCellSize(int p)
          Sets cell size.
 void setShape(Shape shape)
          Set the new shape
 void setSpeed(int fps)
          Set speed of new generations.
 void shapeSelected(GameOfLifeControlsEvent e)
          Callback from GameOfLifeControlsListener
private  void showGenerations()
          Show number of generations.
 void speedChanged(GameOfLifeControlsEvent e)
          Callback from GameOfLifeControlsListener
 void start2()
          Starts creating new generations.
 void startStopButtonClicked(GameOfLifeControlsEvent e)
          Callback from GameOfLifeControlsListener
 void stop()
           
 void zoomChanged(GameOfLifeControlsEvent e)
          Callback from GameOfLifeControlsListener
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gameOfLifeCanvas

protected CellGridCanvas gameOfLifeCanvas

gameOfLifeGrid

protected GameOfLifeGrid gameOfLifeGrid

cellSize

protected int cellSize

cellCols

protected int cellCols

cellRows

protected int cellRows

genTime

protected int genTime

controls

protected GameOfLifeControls controls

gameThread

protected static java.lang.Thread gameThread
Constructor Detail

GameOfLife

public GameOfLife()
Method Detail

init

public void init()
Initialize UI.

See Also:
Applet.init()

getParams

protected void getParams()
Get params (cellSize, cellCols, cellRows, genTime) from applet-tag


getParamInteger

protected int getParamInteger(java.lang.String name,
                              int defaultParam)
Read applet parameter (int) or, when unavailable, get default value.

Parameters:
name - name of parameter
defaultParam - default when parameter is unavailable
Returns:
value of parameter

start2

public void start2()
Starts creating new generations. No start() to prevent starting immediately.


stop

public void stop()
See Also:
Applet.stop()

run

public void run()
Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

isRunning

public boolean isRunning()
Is the applet running?

Returns:
true: applet is running

nextGeneration

public void nextGeneration()
Go to the next generation.


setShape

public void setShape(Shape shape)
Set the new shape

Parameters:
shape - name of shape

reset

public void reset()
Resets applet (after loading new shape)


getAppletInfo

public java.lang.String getAppletInfo()
See Also:
Applet.getAppletInfo()

showGenerations

private void showGenerations()
Show number of generations.


setSpeed

public void setSpeed(int fps)
Set speed of new generations.

Parameters:
fps - generations per second

setCellSize

public void setCellSize(int p)
Sets cell size.

Parameters:
p - size of cell in pixels

getCellSize

public int getCellSize()
Gets cell size.

Returns:
size of cell

alert

public void alert(java.lang.String s)
Shows an alert

Parameters:
s - text to show

startStopButtonClicked

public void startStopButtonClicked(GameOfLifeControlsEvent e)
Callback from GameOfLifeControlsListener

Specified by:
startStopButtonClicked in interface GameOfLifeControlsListener
Parameters:
e - event object
See Also:
GameOfLifeControlsListener.startStopButtonClicked(org.bitstorm.gameoflife.GameOfLifeControlsEvent)

nextButtonClicked

public void nextButtonClicked(GameOfLifeControlsEvent e)
Callback from GameOfLifeControlsListener

Specified by:
nextButtonClicked in interface GameOfLifeControlsListener
Parameters:
e - event object
See Also:
GameOfLifeControlsListener.nextButtonClicked(org.bitstorm.gameoflife.GameOfLifeControlsEvent)

speedChanged

public void speedChanged(GameOfLifeControlsEvent e)
Callback from GameOfLifeControlsListener

Specified by:
speedChanged in interface GameOfLifeControlsListener
Parameters:
e - event object
See Also:
GameOfLifeControlsListener.speedChanged(org.bitstorm.gameoflife.GameOfLifeControlsEvent)

zoomChanged

public void zoomChanged(GameOfLifeControlsEvent e)
Callback from GameOfLifeControlsListener

Specified by:
zoomChanged in interface GameOfLifeControlsListener
Parameters:
e - event object
See Also:
GameOfLifeControlsListener.speedChanged(org.bitstorm.gameoflife.GameOfLifeControlsEvent)

shapeSelected

public void shapeSelected(GameOfLifeControlsEvent e)
Callback from GameOfLifeControlsListener

Specified by:
shapeSelected in interface GameOfLifeControlsListener
Parameters:
e - event object
See Also:
GameOfLifeControlsListener.shapeSelected(org.bitstorm.gameoflife.GameOfLifeControlsEvent)

Game of Life 1.5

This API descibes the Game of Life program, written by Edwin Martin. The source code is available online too.

Copyright 1996-2004 Edwin Martin <edwin@bitstorm.org>.