The source code is all contained in the following files:
This code is an example of the Model-View-Controller design pattern, where the class Fractal is the Controller.
Here are some UML models to help visualize the object-oriented design...
The following is for technical people only...
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.
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:
CODE = "fractal.Fractal.class"
WIDTH = 800
HEIGHT = 600 >
< PARAM NAME = "ImageWidth" VALUE = 470 >
< PARAM NAME = "ImageHeight" VALUE = 470 >
< PARAM NAME = "NumColors" VALUE = 512 >
< /applet >
Here's the Fractal Applet in Romanian (code and all), thanks to Ioan Virag.
If you reuse this code, please give an appropriate reference to the source. Thanks, David