Fractal Applet source code:
This Fractal Applet was developed as an example of Object-Oriented Design for the University of Colorado course CSCI-4448. Modern browsers do not support Java applets anymore, so look to the newer JavaScript Fractal Explorer for code that actually runs. This original version stil serves as a good example of OO programming however, an example of the Model-View-Controller design pattern.

This program is multi-threaded. There are Java AWT threads that call into this code to paint() and notify of events such as mouse movements and button clicks. There are also calls that originate from the browser such as init() and stop(). And there is a thread to calculate each new Fractal. The code uses a single "monitor" object, the single instance of class Fractal, to control thread synchronization.


The source code is all contained in the following files:

fractal.Fractal.java
fractal.ControlPanel.java
fractal.Drawing.java
fractal.DrawingCanvas.java
fractal.FastColorsCalculator.java
fractal.FractalCalculator.java
fractal.HelpDrawing.java
fractal.JuliaCalculator.java
fractal.JuliaDrawing.java
fractal.MandelbrotCalculator.java
fractal.utils.ComplexPoint.java
fractal.utils.ComplexRectangle.java
fractal.utils.IntWrapper.java

Here are some UML models to help visualize the object-oriented design...

This code runs as an Applet and as an Application. The advantages of the Application version are: easier testing during development, control over the image size and the number of colors, and the theoretical ability to save images to disk (for security reasons, Java Applets are not allowed access to your hard drive). To code this last feature, add a SaveButton to the ControlPanel that invokes fractal.doSave() - this gets a BuffferedImage from the currentDrawing; you'll need to use a javax.swing.JFileChooser for the user to select a directory for the image; then do this: javax.imageio.ImageIO.write(theBufferedImage, "PNG", theSelectedFile);.

To download the Application source code, click HERE.

Here is an example command line (-w and -h set the image size in pixels; -c sets the number of colors): java fractal.Fractal -w 800 -h 800 -c 1024

For the Applet version, there are two size parameters that must be set in harmony with each other: the Applet's height and width plus DrawingCanvas' ImageHeight and ImageWidth.

Here is the HTML used to configure these values:

< applet
  CODE = "fractal.Fractal.class"
  WIDTH = 800
  HEIGHT = 600 >
< PARAM NAME = "ImageWidth" VALUE = 470 >
< PARAM NAME = "ImageHeight" VALUE = 470 >
< PARAM NAME = "NumColors" VALUE = 512 >
< /applet >