Java Abstract Window Toolkit tutorial for beginners

In this topic, you will learn about, Java Abstract Window Toolkit tutorial for beginners.

AWT represents the Abstract Window Toolkit. It is a stage subordinate API for making Graphical User Interface (GUI) for Java programs.

Why AWT is stage subordinate? Java AWT calls the local stage (Operating frameworks) subroutine for making segments, for example, textbox, checkbox, button, and so on. For instance, an AWT GUI having a catch would have an alternate look and feel across stages like Windows, Mac OS, and Unix, this is on the grounds that these stages have diverse look and feel for their local catches and AWT legitimately considers their local subroutine that makes the catch. In basic, an application expands on AWT would resemble a windows application when it runs on Windows, yet a similar application would resemble a Mac application when runs on Mac OS

AWT is once in a while utilized nowadays in view of its foundation reliant and overwhelming weight nature. AWT segments are viewed as substantial weight since they are being produced by a fundamental working framework (OS). For instance, on the off chance that you are launching a book enclose AWT that implies you are really requesting that OS make a book box for you.

Swing is a favored API for window-based applications as a result of its foundation free and light-weight nature. Swing is based upon AWT API anyway it gives a look and feels random to the hidden stage. It has more remarkable and adaptable parts than AWT. Notwithstanding natural segments, for example, catches, checkboxes, and marks, Swing gives a few propelled segments, for example, selected board, scroll sheets, trees, tables, and records. We will examine Swing in detail in a different instructional exercise.

See also  Labeled loops used in Java

JAVA AWT hierarchy:

JAVA AWT hierarchy
JAVA AWT hierarchy

AWT Components and containers:

All the components like catches, content fields, scrollbars, and so forth are known as parts. In AWT we have classes for every part as appeared in the above graph. To have everything set on a screen to a specific position, we need to add them to a holder. A compartment resembles a screen wherein we are putting parts like catches, content fields, checkboxes, and so on. In short, a compartment contains and controls the design of segments. A compartment itself is a segment (appeared in the above progressive system graph) hence we can include a holder inside the holder.

Types of containers:

As clarified over, a holder is a spot wherein we include parts like a content field, button, checkbox, and so on. There are four sorts of holders accessible in AWT: Window, Frame, Canvas, and Panel. As appeared in the pecking order outline above, Frame and Canvas are subclasses of Window class.

Component: This is the top hierarchy class for all the AWT components. This is an abstract class that contains all the classes and methods of window components. This class also defines event classes and listener interface that are responsible for managing different and also responsible for placing and resizing the components, setting colors and fonts, etc. this class has some important methods for positioning and resizing the components after they had been added these methods are:


Void setLocation (int x-axis, int y-axis)
void setSize (int width, int height)
Void SetBound (int x-axis, int y-axis, int width, int height)

The (setBound) methods are only applicable when the layout is set to NULL.

See also  Difference between AWT and Swing

Containers: this class is the subclass of the Component. It is mainly responsible for positioning components on a window by using a different layout manager. This class provides the facility of nesting of one object into another container class having the following methods to add and remove components to and from a window:


Void add (component cobj);
Void remove (component cobj);

Window: this class is a base class for the two top-level window class i.e. Panel and Frame. We cannot place any component object into the window. Generally, we create a panel or frame object as a top-level window and place a different component on them.

Panel: this class implement container. A panel is a group of components that is used recursively and nested inside a frame or applet. A panel does not have any border title bar and menu bar. This is where it differs from a frame. We simply add components into a panel and then add this panel into a frame or applet by using add ( ) method.

Frame: A frame is an actual standalone window that has a border, title bar, menu bar, and resizes corners. It is a top-level window that has component objects in it. The role of the frame is the same as the form in Visual basic.
Canvas: The Canvas Is a Black window on which we can draw different graphical objects.

Java AWT Example:

We can make a GUI utilizing Frame in two different ways:

  1. By expanding Frame class
  2. By making the occasion of Frame class
  3. Let us view the case of every one.

Comment below if you have queries related to the above topic, Java Abstract Window Toolkit tutorial for beginners.