Java Reference
In-Depth Information
The program in Listing 9.3 uses the application framework created earlier in this lesson.
A panel is created, three buttons are added to the panel, and then it is added to a frame.
LISTING 9.3
The Full Text of ButtonFrame.java
1: import javax.swing.*;
2:
3: public class ButtonFrame extends JFrame {
4: JButton load = new JButton(“Load”);
5: JButton save = new JButton(“Save”);
6: JButton unsubscribe = new JButton(“Unsubscribe”);
7:
8: public ButtonFrame() {
9: super(“Button Frame”);
10: setSize(140, 170);
11: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12: JPanel pane = new JPanel();
13: pane.add(load);
14: pane.add(save);
15: pane.add(unsubscribe);
16: add(pane);
17: setVisible(true);
18: }
19:
20: public static void main(String[] arguments) {
21: ButtonFrame bf = new ButtonFrame();
22: }
23: }
9
When you run the application, a small frame opens that contains the three buttons (see
Figure 9.2).
FIGURE 9.2
The ButtonFrame
application.
The ButtonFrame class has three instance variables: the load , save , and unsubscribe
JButton objects.
 
Search WWH ::




Custom Search