Source of BorderLayoutDemo.java


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