awt in java free

awt in java 
java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.

AWT

AWT contains a large number of classes and methods that allow you to create and manage windows GUI application. AWT is the foundation upon which Swing is made. It is used for GUI programming in Java. 
awt in java

But nowadays it is merely used because most GUI java programs are implemented using Swing because of its rich implementation of GUI controls and light-weighted nature.

AWT Hierarchy


light-weighted nature.  AWT Hierarchy










Component class

Component class is at the top of the AWT hierarchy. A component is an abstract class that encapsulates all attribute of the visual component. A component object is responsible for remembering the current foreground and background colors and the currently selected text font.

Container

The container is a component in AWT that contains another component like button, text field, tables etc. A container is a subclass of component class. Container class keeps track of components that are added to another component.

Panel

Panel class is a concrete subclass of Container. The panel does not contain a title bar, menu bar or border.

Window class

Window class creates a top-level window. A window does not have borders and menubar.

Frame

A frame is a subclass of Window and has resizing canvas. It is a container that contains several different components like button, title bar, text field, label etc. In Java, most of the AWT applications are created using Frame window. Frame class has two different constructors,
Frame() throws HeadlessException 

Frame(String title) throws HeadlessException 

Creating a Frame

There are two ways to create a Frame. They are,
  • By Instantiating Frame class
  • By extending Frame class creating frame window

    Instantiating Frame class

    import java.awt.*;
    public class Testawt 
    {
     Testawt()
     {
      Frame fm=new Frame();         //Creating a frame.
      Label lb = new Label("welcome to java graphics");     //Creating a label
      fm.add(lb);                //adding label to the frame.
      fm.setSize(300, 300);               //setting frame size.
      fm.setVisible(true);                //set frame visibilty true.
     }
     public static void main(String args[])
     {
      Testawt ta = new Testawt(); 
     }
    }
    Creating Frame Window by Instantiating Frame class




















    Creating a Frame window by extending Frame class

    package testawt;
    
    import java.awt.*;
    import java.awt.event.*;
    
    public class Testawt extends Frame 
    {
      public Testawt() 
     {
      
      Button btn=new Button("Hello World");  
      add(btn);   //adding a new Button.
      setSize(400, 500);        //setting size.
      setTitle("StudyTonight");  //setting title.
      setLayout(new FlowLayout());  //set default layout for frame.    
      setVisible(true);           //set frame visibilty true.    
      
     }
     
     public static void main (String[] args)
     {
      Testawt ta = new Testawt();   //creating a frame.
     }
    }
    
    

    Creating Frame window by extending Frame class






















    Comments