Java Reference
In-Depth Information
This was the last task to be done to complete “version 1.0” of our image-viewer application.
If you have done all the exercises, you should now have a version of the project that can open
images, apply filters, display status messages, and display a dialog.
The imageviewer1-0 project, included in the topic projects, contains an implementation of all
the functionality discussed thus far. You should carefully study this project and compare it with
your own solutions.
In this project, we have also improved the openFile method to include better notification of
errors. If the user chooses a file that is not a valid image file, we now show a proper error mes-
sage. Now that we know about message dialogs, this is easy to do.
11.5.7
Summary of layout management
In this section, we have added some custom classes to deal with images, but more impor-
tantly for our GUI, we have looked at the layout of components. We have seen how con-
tainers and layout managers work together to achieve the exact arrangement we need on
screen.
Learning to work with layout managers takes some experience and often some trial-
and-error experimentation. Over time, however, you will get to know the layout managers
well.
We have now covered the basics of all important areas of GUI programming. For the rest of the
chapter, we can concentrate on fine-tuning and improving what we've got.
11.6
ImageViewer 2.0: improving program
structure
Version 1.0 of our application has a useable GUI and can display images. It can also apply three
basic filters.
The next obvious idea for an improvement of our application is to add some more-
interesting filters. Before we rush in and do it, however, let us think about what this
involves.
With the current structure of filters, we have to do three things for each filter:
1
add a menu item
2
add a method to handle the menu activation in ImageViewer
3
add an implementation of the filter in OFImage
Numbers 1 and 3 are unavoidable—we need a menu item and a filter implementation. But
number 2 looks suspicious. If we look at these methods in the ImageViewer class (Code 11.10
shows two of them as an example), this looks a lot like code duplication. These methods are
essentially the same (except for some small details), and for each new filter we have to add an-
other one of these methods.
 
 
Search WWH ::




Custom Search