Source of FlowLayoutDemo.java


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