Java Reference
In-Depth Information
LISTING 9.4
Continued
18: subscribe = new JButton(“Subscribe”, subscribeIcon);
19: unsubscribe = new JButton(“Unsubscribe”, unsubscribeIcon);
20: // add buttons to panel
21: panel.add(load);
22: panel.add(save);
23: panel.add(subscribe);
24: panel.add(unsubscribe);
25: // add the panel to a frame
26: add(panel);
27: pack();
28: setVisible(true);
29: }
30:
31: public static void main(String[] arguments) {
32: IconFrame ike = new IconFrame();
33: }
34: }
Figure 9.3 shows the result.
FIGURE 9.3
An interface con-
taining buttons
labeled with icons.
The icons' graphics referred to in lines 11-14 can be found on this topic's official web-
site at http://www.java21days.com on the Day 9 page.
The IconFrame application does not set the size of the frame in pixels. Instead, the
pack() method is called in line 27 to expand the frame to the minimum size required to
present the four buttons next to each other.
If the frame were set to be tall rather than wide—for instance, by calling setSize(100,
400) in the constructor—the buttons would be stacked vertically.
Some of the project's graphics are from Sun's Java Look and Feel
Graphics Repository, a collection of icons suitable for use in your
own programs. If you're looking for icons to experiment with in
Swing applications, you can find the icons at the following
address:
NOTE
http://java.sun.com/developer/techDocs/hi/repository
 
Search WWH ::




Custom Search