Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples

April 11, 2016 Categories: AWT. No Comments on Introduction to AWT

In this article we will look at a brief introduction to AWT which is a package used for creating GUIs and is a foundation for more advanced classes.

 

AWT (Abstract Window Toolkit) was Java’s first GUI framework, which was introduced in Java 1.0. It is used to create GUIs (Graphical User Interfaces). Although programmers use more advanced frameworks like Swings and JavaFX, it is important to know that they are built on top of AWT.

 

AWT Classes

The AWT framework contains many classes and interfaces using which we can create GUIs. The AWT package is java.awt. Some of the frequently used AWT classes are listed below:

awt-classes

Various classes in java.awt package are arranged in a hierarchy as shown below:

awt-hierarchy

 

Component and Container

The Component is the abstract root class for many GUI control classes. Container is a sub class of Component class. The Component and various Container classes are arranged in a hierarchy as shown below:

component-container-hierarchy

 

 

Component

Component is the abstract class that encapsulates all the properties of a visual component. Except for menus, most of the GUI components are inherited from the Component class.

 

Container

Container is a sub class of the Component class which can be used to hold other components. A Container object can hold other Containers also. A Container is responsible for laying out (positioning) the components.

 

Panel

Panel class is a concrete sub class of the Container class. A Panel object is a window without title bar, menu bar and border. Panel is the super class of Applet class and is capable of holding other components or containers.

 

Window

Window is a sub class of Container class. A Window creates a top-level container which can hold other components or containers.

 

Frame

Frame is a concrete sub class of Window class. The Frame encapsulates a window. Frame contains a title bar, menu bar, borders and resizable corners. To create stand alone applications in Java, we generally use Frame.

 

Canvas

Canvas class is derived from the Component class. A Canvas encapsulates a blank window on which we can draw.

 

Frame Class

The Frame class is used to create standard windows. Following are two Frame class constructors:

Frame()

Frame(String title)

Following are some of the frequently used methods of Frame class:

void setSize(int width, int height) – Used to specify the width and height of the frame window.

void setSize(Dimension reference) – Used to specify the dimensions of the frame window.

Dimension getSize() – Returns the dimensions of the frame window.

void setVisible(boolean visibleFlag) – Makes the frame window visible or non-visible based on the boolean parameter.

void setTitle(String title) – Used to set the title of the frame window.

Following is Java code for creating a simple frame window:

 

Related Links:

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up