public class TestGUISwing7
1: //TestGUISwing7.java
2: //Add two buttons to a panel and add a panel to the frame.
3: //Then add another button to the frame, but make use of the
4: //fact that the default layout is BorderLayout to position
5: //this third button in the CENTER position of the border layout.
7: import java.awt.*;
8: import java.awt.event.*;
9: import javax.swing.*;
11: public class TestGUISwing7
12: {
13: public static void main(String[] args)
14: {
15: JFrame frame = new JFrame("My JFrame");
16: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18: JPanel panel = new JPanel();
19: JButton b1 = new JButton("First");
20: JButton b2 = new JButton("Second");
21: panel.add(b1);
22: panel.add(b2);
23: frame.getContentPane().add(panel);
24:
25: JButton b3 = new JButton("Third");
26: frame.getContentPane().add(b3, BorderLayout.CENTER);
28: frame.pack();
29: frame.show();
30: }
31: }