Java Reference
In-Depth Information
Figure 16.9 Demonstration of split panes in application SplitPaneFrame
The control part of the application allows the user to select an image from the
list on the left and display it in the lower right area. To this end he or she has
to select a file name in the list and press the button that is embedded into the
frame's 'South' position. The control part is here implemented as an anonymous
listener. The program checks whether the selected file has an extension which
indicates an image file. Only files with extensions .jpg or .png are loaded; other
selections are ignored. One of the images, the one of the orange, is available as
an uncompressed PNG-format and a strongly compressed JPG-format. Loading
the latter into the lower right component and comparing it with the constantly
displayed PNG-image at the upper right makes the loss of quality visible. We list
the program below and a screen shot is shown in Figure 16.9.
File: its/SplitPanes/SplitPaneFrame.java
1.
package its.SplitPanes;
2.
3.
import its.SimpleFrame.SimpleFrame;
4.
import java.awt.*;
5.
import java.awt.event.ActionEvent;
6.
import java.awt.event.ActionListener;
7.
import java.io.File;
8.
import javax.swing.*;
9.
10.
public class SplitPaneFrame extends SimpleFrame
{
11.
private JButton okButton;
12.
private JList list;
13.
private JLabel picLabel1, picLabel2;
14.
private ImageIcon picture1, picture2;
15.
16.
Search WWH ::




Custom Search