BattleLines Java Applet

This is essentially the first home work assignment from a graduate Computer Science course entitled Operating Systems I. This particular applet is actually quite a bit more complicated than the homework assignment was. The homework assignment was to simply write a program that looked like and performed like one cycle of the applet shown below. This applet is more complicated than the homework since it is coded in a much more modular fashion than the homework required. I wrote the original program last October 1998 or so when I got the first homework assignment for that course. I thought that it would be a good idea to put that home work assignment on the web so that you all can see what Computer Science students do while at school !

This code was written in Java version 1.2 but not much of the code is really that different than Java 1.1 or Java 1.0 as far as I know. This applet is actually broken up into three modular pieces. The pieces are :

miscellaneous utility module

This module contains some utility subroutines that really do not have to belong in any class so I assembled them into a Java Package for miscellaneous access.

a MovingLines graphic component

This module implements a public class (along with some privately used helper classes) that make up what you are actually looking at (for the most part). This module is almost as simple as the homework assignment was but not quite. This graphical component is similar to a Java Bean and can be added to other Container Components as needed. The applet shown below has a single child component added to the Applet Panel Container component that the web browser you are running created. The child component is this MovingLines component described here. This component is supposed to make a specified number of lines with random colors (not too close to the background so you can see them !), random orientations, and random directions. All of the lines have the same speed (but of course different velocities). The idea is that whenever two lines intersect, one of them is killed off. The lines are moved by a background thread within the class. The thread is controlled by the outer applet that added this class component to its container. The interface of this module is similar to that of a standard applet.

the BattleLines java applet

The last module making up this whole applet is an Applet class extension named BattleLines. This module adds the MovingLines component described above to the applet container and then initializes it, starts it, and then continuously monitors its progress with a background thread. The background thread is monitoring how many lines are left (by asking the MovingLines component for a status update) and also monitors the length of time since a line was last killed off. If the number of lines left alive drops below a specified threshold or the number of lines left has not changed, then if the time since the last line kill has exceeded a threshold, the MovingLines component is stopped, destroyed, re-initialized, and started again. This cycle repeats indefinitely until you ask your browser program to switch to another page. Some browsers out there are supposed to try and do something intelligent when your browser window gets covered up by another window (or something similar). It is supposed to ask this applet to STOP. This applet actually does something useful with this and puts its own background monitoring thread into a suspended state and also sends a message (subroutine call in this new fangled object oriented programming lingo) to the MovingLines component to STOP also. It obliges and suspends its background thread also. This all serves to save those precious computing cycles on your machine so that it doesn't get bogged down while this applet is otherwise not being seen by a human being.

Quality of rendering

Firstly, this animation is NOT double buffered. This means that depending on your system, you may (will probably) see some flickering of the lines as they move about. This could be mostly solved with the use of double buffering of the animation. Note that it appears that the Netscape browser applies some sort of internal double buffering of its own so the whole thing probably looks best when viewed with a Netscape browser. The string 'COMPUTER SCIENCE' is supposed to get erased by the lines traveling over the string.

BattleLines Java Applet

Operating Systems I -- October 1998