Java Reference
In-Depth Information
LISTING 11.2
The Full Text of Stacker.java
1: import java.awt.*;
2: import javax.swing.*;
3:
4: public class Stacker extends JFrame {
5: public Stacker() {
6: super(“Stacker”);
7: setSize(430, 150);
8: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9: // create top panel
10: JPanel commandPane = new JPanel();
11: BoxLayout horizontal = new BoxLayout(commandPane,
12: BoxLayout.X_AXIS);
13: commandPane.setLayout(horizontal);
14: JButton subscribe = new JButton(“Subscribe”);
15: JButton unsubscribe = new JButton(“Unsubscribe”);
16: JButton refresh = new JButton(“Refresh”);
17: JButton save = new JButton(“Save”);
18: commandPane.add(subscribe);
19: commandPane.add(unsubscribe);
20: commandPane.add(refresh);
21: commandPane.add(save);
22: // create bottom panel
23: JPanel textPane = new JPanel();
24: JTextArea text = new JTextArea(4, 70);
25: JScrollPane scrollPane = new JScrollPane(text);
26: // put them together
27: FlowLayout flow = new FlowLayout();
28: setLayout(flow);
29: add(commandPane);
30: add(scrollPane);
31: setVisible(true);
32: }
33:
34: public static void main(String[] arguments) {
35: Stacker st = new Stacker();
36: }
37: }
When the class is compiled and run, the output should resemble Figure 11.2.
FIGURE 11.2
A user interface
with buttons
arranged with
the box layout
manager.
 
Search WWH ::




Custom Search