The source code:
Animator.java
Class that runs and animates the simulation.
AntFood.java
Class that contains the amount of food external to the colony.
AntSim.java
Class that controls all the other classes.
CheckboxPanel.java
Class that constructs the checkbox panel.
Colony.java
Class that contains all the methods and information needed to run the
simulation for one turn.
Colors.java
Class that constructs the color choice panel.
Predators.java
Class that contains the menthods and information need to attack the
colony.
Random.java
Class that generates a random number between two integer values.
Variables.java
Class that constructs the change parameters panel.
Mythology on the Web
My homepage.
Author: Richard L. Koshak
Professor George Luger
Language: Sun Java 1.0
Java Simulation
The applet below is a translation of the ant colony simulation I wrote in Lisp. The ant colony goes through a fixed set of behaviors each turn: eating, foraging for food, laying eggs, hatching, and defending the colony from predators. Most of these behaviors have a high degree of randomization such as a random number of turns until an egg hatches.
Writing the GUI for this program went through several stages. To start, I took the code of an applet in the Java Tutorial provided by Sun and played around with it, seeing how things change as I changed values. Once I figured out how to layout a GUI I made a GUI to look the way I wanted it to look. Once I figured that out I tried to figure out animation because I wanted my graphs to be animated from the start. When I got some example code for that I decided to start over with a new program running as an aplication. I finally figured out how to do animation and got the animation class to draw graphs (I used buffering to stop flashing and code I wrote for the function plotter I wrote for CS 341 as a template for plotting the graphs to scale.)
Once I got the animation to work I made a design decision. I decided to have this program run as either an application or as an applet so I used the template in the handout we got in class (if run as an application it creates a frame and runs the applet in it). I later realized the consequences of this decision.
Because all the work is done in an applet I was unable to use a menu or dialogs like I originally planned. At this point I could either change the foudation of the program yet again so the applet opens a frame or work around it. I decided to work around it to save time adn effort (even the modularity of the program makes it a simple matter to make it work the other way). To work around it I used buttons instead of menues and I replaced the contents of the screen rather then using dialogs and I used a label to handle the error messages.
Everything else is pretty much self explaintary, if not I'll explain it when I present it.