Java Reference
In-Depth Information
Code 11.5
Using a Border
Layout to arrange
contentPane = frame.getContentPane();
contentPane.setLayout( new BorderLayout());
filenameLabel = new JLabel();
contentPane.add(filenameLabel, BorderLayout.NORTH);
imagePanel = new ImagePanel();
contentPane.add(imagePanel, BorderLayout.CENTER);
statusLabel = new JLabel( "Version 1.0" );
contentPane.add(statusLabel, BorderLayout.SOUTH);
Exercise 11.21 Implement and test the code shown above in your version of the project.
Exercise 11.22 Experiment with other layout managers. Try in your project all of the layout
managers mentioned above, and test whether they behave as expected.
Image filters
Two things remain to be done before our first image-viewer version is finished: adding some
image filters and adding a Help menu. Next, we shall do the filters.
The image filters are the first step toward image manipulation. Eventually, we want not only to
be able to open and display images, but also to be able to manipulate them and save them back
to disk.
Here, we start by adding three simple filters. A filter is a function that is applied to the whole
image. (It could, of course, be modified to be applied to a part of an image, but we are not doing
that just yet.)
The three filters are named darker , lighter , and threshold. Darker makes the whole image
darker, and lighter makes it lighter. The threshold filter turns the image into a grayscale picture
with only a few preset shades of gray. We have chosen a three-level threshold. This means we
shall use three colors: black, white, and medium-gray. All pixels that are in the upper-third
value range for brightness will be turned white, all that are in the lower third will be turned
black, and the middle third will be gray.
To achieve this, we have to do two things:
create menu items for each filter with an associated menu listener
implement the actual filter operation
First the menus. There is nothing really new in this. It is just more of the same menu-creation
code that we already wrote for our existing menu.
Search WWH ::

Custom Search