// Exercise 12.8 Solution

// Align.java

// This program creates a simple GUI

import javax.swing.*;

import java.awt.*;



public class Align extends JApplet {

   private JButton ok, cancel, help;

   private JTextField xValue, yValue;

   private JCheckBox snap, show;

   private JLabel xLabel, yLabel;

   private JPanel checkPanel, buttonPanel,

                  fieldPanel1, fieldPanel2,

                  fieldPanel;



   public void init()

   {

      // build checkPanel

      snap = new JCheckBox( "Snap to Grid" );

      show = new JCheckBox( "Show Grid" );

      checkPanel = new JPanel();

      checkPanel.setLayout( new GridLayout( 2 , 1 ) );

      checkPanel.add( snap );

      checkPanel.add( show );



      // build field panel1

      xLabel = new JLabel( "X: " );

      xValue = new JTextField( "8", 3 );

      fieldPanel1 = new JPanel();

      fieldPanel1.setLayout( new FlowLayout( FlowLayout.CENTER, 3, 5 ) );

      fieldPanel1.add( xLabel );

      fieldPanel1.add( xValue );



      yLabel = new JLabel( "Y: " );

      yValue = new JTextField( "8", 3 );

      fieldPanel2 = new JPanel();

      fieldPanel2.setLayout( new FlowLayout( FlowLayout.CENTER, 3, 5 ) );

      fieldPanel2.add( yLabel );

      fieldPanel2.add( yValue );



      fieldPanel = new JPanel();

      fieldPanel.setLayout( new BorderLayout() );

      fieldPanel.add( fieldPanel1, BorderLayout.NORTH );

      fieldPanel.add( fieldPanel2, BorderLayout.SOUTH );



      // build button panel

      ok = new JButton( "Ok" );

      cancel = new JButton( "Cancel" );

      help = new JButton( "Help" );

      buttonPanel = new JPanel();

      buttonPanel.setLayout( new GridLayout( 3, 1, 10, 5 ) );

      buttonPanel.add( ok );

      buttonPanel.add( cancel );

      buttonPanel.add( help );



      // set layout for applet

      getContentPane().setLayout(

            new FlowLayout( FlowLayout.CENTER, 10, 5 ) );

      getContentPane().add( checkPanel );

      getContentPane().add( fieldPanel );

      getContentPane().add( buttonPanel );

   }

}
