// File LayoutDemo.java
// CSCI E-50b, Unit 6
// Illustrate several types of Layout Managers (as well as some Borders)

import javax.swing.*;
import java.awt.*;

class LayoutDemo
{
   public static void main (String args[])
   {
      // System.out.println(UIManager.getLookAndFeel());
 	  JButton [] jB = new JButton [16];
 	  for (int i = 0; i < 16; i++ )
 	  {
 	      jB[i] = new JButton  ("Button #"+(i+1));
 	      jB[i].setFont(new Font ("Times", Font.BOLD, 24));
 	  }
 	  for (int i = 0; i < 16; i+=4)
 	  {
 	      jB[i].setBackground(Color.RED);
 	      jB[i].setBorder(BorderFactory.createTitledBorder("Foobar"));
 	      jB[i+1].setBackground(Color.YELLOW);
 	      jB[i+1].setBorder(BorderFactory.createLoweredBevelBorder());
 	      jB[i+2].setBackground(Color.BLUE);
 	      jB[i+3].setBackground(Color.GREEN);
 	   } 
           
      JFrame jf1 = new JFrame("JFrame with FlowLayout");
      jf1.setSize(100, 100);
      Container c = jf1.getContentPane();
      c.setLayout ( new FlowLayout() );
      for (int i=0; i < 4; i++)  c.add( jB[i] );
      jf1.setVisible(true);
      
      JFrame jf2 = new JFrame("JFrame with BorderLayout");
      jf2.setSize(100, 100);
      c = jf2.getContentPane();
      c.setLayout( new BorderLayout() ); // although BorderLayout is the default!
      c.add( jB[4], BorderLayout.WEST);
      c.add( jB[5], BorderLayout.SOUTH);
      c.add( jB[6], BorderLayout.CENTER);
      c.add( jB[7], BorderLayout.NORTH);
      jf2.setVisible(true);
      
      JFrame jf3 = new JFrame("JFrame with GridLayout");
      jf3.setSize(100, 100);
      c = jf3.getContentPane();
      c.setLayout( new GridLayout(2, 6, 3, 3) );
      for (int i = 8; i < 12; i++) c.add( jB[i] );
      jf3.setVisible(true);
      
      JFrame jf4 = new JFrame("JFrame with BoxLayout");
      jf4.setSize(100, 100);
      c = jf4.getContentPane();
      jf4.setLayout( new BoxLayout(c, BoxLayout.X_AXIS) );
      for (int i = 12; i < 16; i++)  c.add( jB[i] );
      jf4.setVisible(true);
   }
}
