import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

/** PC_LayoutExample - programming challenge on layout.<p>
*
* <b>Programming Challenge:</b><br>
* Write a java GUI application to create the
* component layout shown below. 
* Make sure the program responds appropriately when the application
* window is resized.  Note, as well, that both buttons should be the
* same size. Name the program <code>PC_LayoutExample.java</code><p>
*
* Screen snap...<br>
* <center><img src = "PC_LayoutExample-1.gif"></center><p>
*
* Screen snap (after resizing)...<br>
* <center><img src = "PC_LayoutExample-2.gif"></center><p>
*
* @see <a href="PC_LayoutExample.java">source code</a>
* @author Scott MacKenzie, 2002
*/
public class PC_LayoutExample
{
   public static void main(String[] args)
   {
      // use system default look and feel
      try {
         UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
      } catch (Exception e) {}

      PC_LayoutExampleFrame frame = new PC_LayoutExampleFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setTitle("PC_LayoutExample");
      frame.pack();
      frame.show();
   }
}

class PC_LayoutExampleFrame extends JFrame
{
   private JLabel label;
   private JButton clear;
   private JButton exit;
   private JTextArea input;

   public PC_LayoutExampleFrame()
   {
      // ----------------------------------
      // construct and configure components
      // ----------------------------------

      label = new JLabel("Enter some text:");
      clear = new JButton("Clear");
      exit = new JButton("Exit");
      exit.setPreferredSize(clear.getPreferredSize());

      input = new JTextArea();
      input.setPreferredSize(new Dimension(200, 100));
      input.setBorder(BorderFactory.createLineBorder(Color.black));
      input.setAlignmentX(Component.LEFT_ALIGNMENT);

      // -----------------
      // layout components
      // -----------------

      JPanel centerPanel = new JPanel();
      centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
      centerPanel.add(label);
      centerPanel.add(Box.createRigidArea(new Dimension(0, 5)));
      centerPanel.add(input);
      centerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

      JPanel buttonPanel = new JPanel();
      buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
      buttonPanel.add(Box.createHorizontalGlue());
      buttonPanel.add(clear);
      buttonPanel.add(Box.createRigidArea(new Dimension(5, 0)));
      buttonPanel.add(exit);
      buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));

      JPanel panel = new JPanel(new BorderLayout());
      panel.add(centerPanel, "Center");
      panel.add(buttonPanel, "South");

      // make panel this JFrame's content pane

      this.setContentPane(panel);
   }
}

