Java Reference
In-Depth Information
Listing 10.3 contains the source code used to produce this application.
LISTING 10.3
The Full Text of FeedBar.java
1: import java.awt.*;
2: import java.awt.event.*;
3: import javax.swing.*;
4:
5: public class FeedBar extends JFrame {
6:
7: public FeedBar() {
8: super(“FeedBar”);
9: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
10: // create icons
11: ImageIcon loadIcon = new ImageIcon(“load.gif”);
12: ImageIcon saveIcon = new ImageIcon(“save.gif”);
13: ImageIcon subscribeIcon = new ImageIcon(“subscribe.gif”);
14: ImageIcon unsubscribeIcon = new ImageIcon(“unsubscribe.gif”);
15: // create buttons
16: JButton load = new JButton(“Load”, loadIcon);
17: JButton save = new JButton(“Save”, saveIcon);
18: JButton subscribe = new JButton(“Subscribe”, subscribeIcon);
19: JButton unsubscribe = new JButton(“Unsubscribe”, unsubscribeIcon);
20: // add buttons to toolbar
21: JToolBar bar = new JToolBar();
22: bar.add(load);
23: bar.add(save);
24: bar.add(subscribe);
25: bar.add(unsubscribe);
26: // prepare user interface
27: JTextArea edit = new JTextArea(8, 40);
28: JScrollPane scroll = new JScrollPane(edit);
29: BorderLayout bord = new BorderLayout();
30: setLayout(bord);
31: add(“North”, bar);
32: add(“Center”, scroll);
33: pack();
34: setVisible(true);
35: }
36:
37: public static void main(String[] arguments) {
38: FeedBar frame = new FeedBar();
39: }
40: }
This application uses four images to represent the graphics on the buttons—the same
graphics used in the IconFrame project yesterday. If you haven't downloaded them yet,
they are available on the topic's official website at http://www.java21days.com on the
 
Search WWH ::




Custom Search