Scott Hurring » Code » Java » Conway's Life » v0.1 alpha

Download Code
download
JavaLife-alpha1.jar
v0.1 beta · May 04, 2004
(browse code)

Description

NOTE: "Start" and "Stop" don't do anything yet. I need to get around to implementing the threads code. However, manually advancing the generations using the "Next" button (or Ctrl+N) works fine.

JavaLife is a swing application that i wrote as extra credit for a Java Programming class that i'm taking this semester. Probably the only reason i actually coded any of this is becuase of Eclipse, which is one hell of an IDE. ;-)

When writing this, i used a "Delegator" approach (its probably got some more official name than what i call it). Basically, the main "JavaLife" class is simply a dumb shell that delegates calls to the different components of the application - Namely the "Engine" and "Field".

The field contains all the cells, and the engine knows how to progress from one generation to the next (the engine is also where i'm going to put in the Threads code so that you can have the simulation advance by itself).

What does it look like?

Overview of Classes in JavaLife

JavaLife.java: The main class, instantiates the MainFrame, LifeField and LifeEngine classes.

LifeField.java: This is the "field", which basically is responsible for setting up a 2D array of rows and cols and then stuffing that full of LifeCell objects. It does *not* compute generations.

LifeCell.java: A single cell. The cell keeps track of its own state and has a list of its neighbors (to make computing each generation very easy). LifeCell extends JLabel becuase i'm lazy and needed something simple that could draw itself and support a coloured background. (If you know of a more elegant way of doing this, let me know.)

LifeEngine.java: The "simulation engine" that knows how to compute from one generation to another.

LifeEngine.java: The "simulation engine" that knows how to compute from one generation to another.


Download

v0.1 alpha - May 04, 2004