
/**
 * This program demonstrates the use of JPanels to
 * 
 * (1) Keep related components together, even if the GUI is resized
 * (2) Allow use of a different layout for a group of components than
 *     for the rest of the GUI
 * (3) Protect components from being stretched
 * 
 * The overall GUI has a BorderLayout, and consists of a title, a series 
 * of boxes for entering information on a person, arranged as a 2 column 
 * grid (caption, box for data entry), plus a series of buttons.
 * 
 * @author Russell C. Bjork
 * @version March 22, 2006
 */

import java.awt.*;
import javax.swing.*;

public class JPanelDemo extends JFrame
{
    public static void main(String [] args)
    {
         JPanelDemo theGUI = new JPanelDemo();
         theGUI.setVisible(true);
    }
        
    /** Constructor
     */
   private JPanelDemo()
   {
       Container pane = getContentPane();
       pane.setLayout(new BorderLayout());

       // Set up the title
       
       JLabel title = new JLabel("Enter/update person information", JLabel.CENTER);
       pane.add(title, BorderLayout.NORTH);
       
       // Set up the panel for editing
       
       JPanel editingPanel = new JPanel();
       editingPanel.setLayout(new FlowLayout());
       JPanel labelsPanel = new JPanel();
       labelsPanel.setLayout(new GridLayout(0, 1));
       JPanel fieldsPanel = new JPanel();
       fieldsPanel.setLayout(new GridLayout(0, 1));
       editingPanel.add(labelsPanel);
       editingPanel.add(fieldsPanel);
       pane.add(editingPanel, BorderLayout.CENTER);
       
       labelsPanel.add(new JLabel("Name"));
       JTextField nameField = new JTextField(30);
       fieldsPanel.add(nameField);
       
       labelsPanel.add(new JLabel("Address"));
       JTextField addressField = new JTextField(30);
       fieldsPanel.add(addressField);

       labelsPanel.add(new JLabel("City"));
       JTextField cityField = new JTextField(30);
       fieldsPanel.add(cityField);
       
       // Set up the buttons
       
       JPanel buttonsPanel = new JPanel();
       buttonsPanel.setLayout(new FlowLayout());
       pane.add(buttonsPanel, BorderLayout.SOUTH);
       
       JButton cancelButton = new JButton("Cancel");
       buttonsPanel.add(cancelButton);
       JButton doneButton = new JButton("Done");
       buttonsPanel.add(doneButton);
       
       pack();
    }
}
