Lab 4: Choosing and Saving Fractals

This week you will extend your Fractal Explorer with two new features. First, you will add support for multiple fractals, and allow the user to select which fractal to display via a dropdown combo-box. Second, you will add support for saving the current fractal image into a data file. Here is a screenshot of what your new program will look like:

The top of the Fractal Explorer now includes two widgets to let the user select a fractal, and the bottom includes a new "Save" button to save the current fractal image.

Since there will now be multiple action-event sources, you can practice handling all of these sources with a single ActionListener implementation in your class.

Supporting Multiple Fractals

It is very easy to add multiple fractals to your Fractal Explorer, particularly because we introduced the FractalGenerator abstraction in our initial implementation. This week you will add support for multiple fractals, and the user can choose between them using a combo-box. This is a very common "UI metaphor" (i.e. an interaction style that users are already familiar with from many different user interfaces), so it should be very easy for people to understand. The Swing API provides combo-boxes via the javax.swing.JComboBox class, and better yet, it fires ActionEvents when a new item is selected. Here is what you need to do:

So that you can verify your work, here are the initial images for the Tricorn and Burning Ship fractals:

Tricorn Fractal Burning Ship Fractal

Saving the Fractal Image

Your other task for this week is to save the current fractal image to disk. This might sound like a daunting task, but the Java API provides several tools to make this very straightforward to implement.

Once you are done with these features, give them a try! You should now be able to explore the various fractals and see them in all their beauty, and you should also be able to save the images of what you see to disk. You can also try out your error-handling code by trying to save an image to a file that already exists but is read-only, or perhaps to a read-only drive like a CD. Or, you can try saving to a file whose name is actually a directory in the target folder.

Once you are convinced that everything works, submit your files to csman.


Updated May 8, 2012. Copyright (C) 2011-2012, California Institute of Technology.