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

/**
 * Create a window with many panels
 * Each panel will have various input fields 
 * place each panel in different location on the window
 */

public class Awindow6 extends JFrame
{                           
    JPanel         panel1     = new JPanel();
    JLabel         nameLabel  = new JLabel("Username: ");    //define fields
    JTextField     name       = new JTextField(17);          //to be displayed
    JLabel         pswdLabel  = new JLabel("Password: ");
    JPasswordField password   = new JPasswordField(17);
    JLabel         cmntLabel  = new JLabel("Comments: ");

    JPanel         panel2     = new JPanel();
    JTextArea      comment    = new JTextArea(5, 17);

    JPanel         panel3     = new JPanel();
    JCheckBox      red        = new JCheckBox("Red",   true);  
    JCheckBox      green      = new JCheckBox("Green", false);  
    JCheckBox      blue       = new JCheckBox("Blue",  false);  

    JPanel         panel4     = new JPanel();
    JRadioButton   line       = new JRadioButton("Line",      true);  
    JRadioButton   rectangle  = new JRadioButton("Rectangle", false);  
    JRadioButton   circle     = new JRadioButton("Circle",    false);  
    JRadioButton   curve      = new JRadioButton("Curve",     false);  

    JPanel         panel5    = new JPanel();
    JLabel         nextline  = new JLabel("            ");    
    JButton        enter     = new JButton("   ENTER   ");
    JButton        cancel    = new JButton("  CANCEL  ");

    public static void main(String[] args)          //called by the JVM
    {
        new Awindow6();                             //instantiate a program object
    }   

    public Awindow6()                               //constructor
    {
        setTitle("JFrame with Multiple JPanels");   //same as this.setTitle
        setBounds(200,50,508,272);                  //position x,y and size w,h 
        setDefaultCloseOperation(EXIT_ON_CLOSE);    //action when you press X

        Container pane = getContentPane();          //get ref to the contentPane

        pane.setLayout(null);                       //no layout manager

        Color c;                                
        
        c = new Color(200,250,250);                 //create a color object
        panel1.setBackground(c);                    //set the background color
        c = new Color(200,250,200);                 //create a color object
        panel2.setBackground(c);                    //set the background color
        c = new Color(200,200,250);                 //create a color object
        panel3.setBackground(c);                    //set the background color
        c = new Color(200,150,250);                 //create a color object
        panel4.setBackground(c);                    //set the background color
        c = new Color(100,150,250);                 //create a color object
        panel5.setBackground(c);                    //set the background color

        comment.setLineWrap(true);                  //set line wrap
        comment.setWrapStyleWord(true);             //set word wrap

        ButtonGroup radioGrp1 = new ButtonGroup();  //create a button group

        radioGrp1.add(line);                        //make them part of a group
        radioGrp1.add(rectangle);
        radioGrp1.add(circle);
        radioGrp1.add(curve);

        panel1.add(nameLabel);                      //add the components
        panel1.add(name);
        panel1.add(pswdLabel);
        panel1.add(password);
        panel2.add(cmntLabel);
        panel2.add(comment);
        panel3.add(red);
        panel3.add(green);
        panel3.add(blue);
        panel4.add(line);
        panel4.add(rectangle);
        panel4.add(circle);
        panel4.add(curve);
        panel4.add(nextline);
        panel5.add(enter);
        panel5.add(cancel);

        panel1.setLayout(new FlowLayout(FlowLayout.LEFT));      //use FlowLayout manager
        panel2.setLayout(new FlowLayout(FlowLayout.LEFT));
        panel3.setLayout(null);                                 //disable default layout manager
        panel4.setLayout(null);                                 //which is FlowLayout  CENTER
        panel5.setLayout(new FlowLayout(FlowLayout.RIGHT));

        pane.add(panel1);                           //add the panels to the window
        pane.add(panel2);
        pane.add(panel3);
        pane.add(panel4);
        pane.add(panel5);

        panel1.setBounds(000,000,300,075);          //position: x,y and size: w,h 
        panel2.setBounds(000,075,300,140);
        panel3.setBounds(300,000,200,100);
        panel4.setBounds(300,100,200,100);
        panel5.setBounds(000,200,500,050);

        red.setBounds   (010,005,100,25);
        green.setBounds (010,030,100,25);
        blue.setBounds  (010,055,100,25);

        line.setBounds     (010,005,100,25);
        rectangle.setBounds(010,030,100,25);
        circle.setBounds   (010,050,100,25);
        curve.setBounds    (010,072,100,25);

//      setResizable(false);
        setVisible(true);   
    }
}