public class BorderLayoutDemo extends JFrame
1: import javax.swing.JFrame;
2: import javax.swing.JLabel;
3: import java.awt.BorderLayout;
4: import java.awt.Container;
5:
6: /**
7: Simple demonstration of using a layout manager
8: to arrange labels.
9: */
10: public class BorderLayoutDemo extends JFrame
11: {
12: public static final int WIDTH = 300;
13: public static final int HEIGHT = 200;
14:
15: public BorderLayoutDemo( )
16: {
17: setSize(WIDTH, HEIGHT);
18: addWindowListener(new WindowDestroyer( ));
19: setTitle("Layout Demonstration");
20: Container content = getContentPane( );
21:
22: content.setLayout(new BorderLayout( ));
23:
24: JLabel label1 = new JLabel("First label here.");
25: content.add(label1, BorderLayout.NORTH);
26:
27: JLabel label2 = new JLabel("Second label there.");
28: content.add(label2, BorderLayout.SOUTH);
29:
30: JLabel label3 = new JLabel("Third label anywhere.");
31: content.add(label3, BorderLayout.CENTER);
32: }
33:
34: /**
35: Creates and displays a window of the class BorderLayoutDemo.
36: */
37: public static void main(String[] args)
38: {
39: BorderLayoutDemo gui = new BorderLayoutDemo( );
40: gui.setVisible(true);
41: }
42: }
43:
44:
45:
46:
47: