Create graphical user interface using classes in java.awt package


In this source code, awt component that include is :
FRAME
BUTTON
PANEL
LABEL
TEXTAREA
TEXTFIELD
CHECKBOX
RADIO BUTTON

layout manager is :
GRID LAYOUT
FLOW LAYOUT

others :
COLOR

****************************************************************
COMPLETE SOURCE CODE FOR : CreatingInterfaceUsingAwt.java
****************************************************************


import java.awt.Frame;//FOR FRAME IN AWT
import java.awt.Button;//FOR BUTTON IN AWT
import java.awt.Panel;//FOR PANEL IN AWT
import java.awt.TextArea;//FOR TEXTAREA IN AWT
import java.awt.TextField;//FOR TEXTFIELD IN AWT
import java.awt.Label;//FOR LABEL IN AWT
import java.awt.List;//FOR LIST IN AWT

//FOR CHECKBOX AND RADIOBUTTON IN AWT
import java.awt.CheckboxGroup;
import java.awt.Checkbox;

//LAYOUT MANAGER
import java.awt.FlowLayout;
import java.awt.GridLayout;

import java.awt.Color;

import java.awt.event.WindowListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class CreatingInterfaceUsingAwt
{
public static void main(String[]args)
{
Frame a=new Frame("All Of This Component Is Build Using Java AWT");
a.setLayout(new FlowLayout());

WindowListener cl=new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);//WHEN CLICK WINDOW CLOSE BUTTON, APPLICATION WILL EXIT
}
};

a.add(new Button("THIS IS BUTTON"));//ADD A BUTTON WITH LABEL "THIS IS BUTTON"
a.add(new Label("THIS IS A LABEL"));//ADD A LABEL WITH SPECIFIED TEXT "THIS IS A LABEL"

//CREATE A PANEL THAT MAY CONTAIN OTHER AWT COMPONENT
Panel b=new Panel(new FlowLayout());//CREATE A PANEL AND SET IT'S LAYOUT
b.setBackground(Color.BLACK);//SET BACKGROUND COLOR FOR THIS PANEL TO BLACK
b.add(new Button("BUTTON_1 IN PANEL"));
b.add(new Button("BUTTON_2 IN PANEL"));
b.add(new Button("BUTTON_3 IN PANEL"));
a.add(b);//ADD THIS PANEL TO FRAME

a.add(new TextArea("THIS IS TEXT AREA"));//ADD A TEXT AREA WITH INITIAL TEXT "THIS IS TEXT AREA"
a.add(new TextField("THIS IS TEXT FIELD"));//ADD A TEXT FIELD WITH INITIAL TEXT "THIS IS TEXT FIELD"

//CREATE CHECKBOX
Panel d=new Panel(new GridLayout(3,1));
d.setBackground(Color.RED);
d.add(new Checkbox("CHECKBOX 1",null,false));//CREATE A CHECKBOX c=checkbox group, false=initial state of checkbox
d.add(new Checkbox("CHECKBOX 2",null,false));//if false, no check for the checkbox in initially
d.add(new Checkbox("CHECKBOX 3",null,false));
a.add(d);//ADD THIS PANEL TO FRAME

//CREATE RADIO BUTTON
Panel e=new Panel(new GridLayout(3,1));
e.setBackground(Color.BLUE);
CheckboxGroup c=new CheckboxGroup();//CREATE A CHECKBOX GROUP
e.add(new Checkbox("RADIOBUTTON 1",c,false));//c=checkbox group
e.add(new Checkbox("RADIOBUTTON 2",c,false));
e.add(new Checkbox("RADIOBUTTON 3",c,false));
a.add(e);//ADD THIS PANEL TO FRAME
//What is different between radio button and checkbox ???
//The different is at CheckboxGroup.
//For radio button, we must set to certain checkbox group(In this case we set c for checkbox group in checkbox argument after checkbox name)

//CREATE LIST
List f=new List(5,true);//If you want to disable multiple selection, you just change true to false
f.add("LIST 1");
f.add("LIST 2");
f.add("LIST 3");
f.add("LIST 4");
f.add("LIST 5");
a.add(f);//ADD THIS PANEL TO FRAME

a.addWindowListener(cl);
a.setSize(800,600);
a.setVisible(true);
}
}


****************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************