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

/**
 * Create a window with a text field, a password field, a textarea 
 * radio buttons, checkboxes, and buttons
 */

public class Awindow5 extends JFrame
{                           
    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: ");
    JTextArea      comment    = new JTextArea(6, 17);

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

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

    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 Awindow5();                             //instantiate a program object
    }   

    public Awindow5()                               //constructor
    {
        setTitle("Window with diff. controls");     //same as this.setTitle()
        setBounds(150,50,300,280);                  //position and size of window   
        setDefaultCloseOperation(EXIT_ON_CLOSE);    //action when you press X

        JPanel pane = new JPanel();                 //or create a JPanel
        setContentPane(pane);                       //and assign contentPane to it

        FlowLayout flow = new FlowLayout(FlowLayout.LEFT);   //force left alignment   
        pane.setLayout(flow);                                //default is center

        Color c = new Color(200,255,255);           //create an RGB color
        pane.setBackground(c);                      //set the background color

        red.setBackground(c);
        green.setBackground(c);
        blue.setBackground(c);
        line.setBackground(c);
        rectangle.setBackground(c);
        circle.setBackground(c);
        curve.setBackground(c);

        c = new Color(250,200,150);                       
        enter.setBackground(c);                     
        cancel.setBackground(c);                    
        c = new Color(50,100,150);      
        enter.setForeground(c);                
        cancel.setForeground(c);                

        Font f = new Font("Arial",Font.BOLD,12);    //PLAIN, ITALIC, BOLD
        enter.setFont(f);                           //set button font
        cancel.setFont(f);

        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);

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

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