Java AWT Tutorial

1. What is AWT in Java? 

AWT stands for Abstract Window Toolkit, which is an API for creating graphical user interface (GUI) or windows-based applications in Java. AWT provides various components like buttons, labels, text fields, etc. that can be used as objects in a Java program

2. What are the advantages of AWT? 

Some of the advantages of AWT are:

  • It is easy to use and learn for beginners.
  • It is compatible with all platforms that support Java.
  • It provides a native look and feel for the components.

3. What are the types of containers in AWT? 

A container is a component that can contain other components. There are four types of containers in AWT:

  • Window: a container that has no borders and menu bars. It requires a frame, dialog, or another window to create it.
  • Panel: a container that has no title bar, border, or menu bar. It is a generic container for holding components.
  • Frame: a container that has a title bar, and border, and can have menu bars. It is the most widely used container for developing AWT applications.
  • Dialog: a container that has a title bar, and border, and can have buttons. It is used to display messages or get user input.

4. How to create and use components in AWT? 

To create and use components in AWT, we need to follow these steps:

  • Import the java.awt package, which contains the classes for AWT components.
  • Create an instance of the component class, such as Button, Label, TextField, etc.
  • Set the properties of the component, such as size, location, text, color, etc.
  • Add the component to a container, such as Frame, Panel, etc.
  • Set the visibility of the container to true.


Java AWT Tutorial

Java AWT or Abstract Window Toolkit is an API used for developing GUI(Graphic User Interfaces) or Window-Based Applications in Java. Java AWT is part of the Java Foundation Classes (JFC) that provides a way to build platform-independent graphical applications.

In this AWT tutorial, you will learn the basics of the AWT, including how to create windows, buttons, labels, and text fields. We will also learn how to add event listeners to components so that they can respond to user input.

By the end of this tutorial, you will have a good understanding of the AWT and be able to create simple GUIs in Java.

Similar Reads

Java AWT Basics

Java AWT (Abstract Window Toolkit) is an API used to create Graphical User Interface (GUI) or Windows-based Java programs and Java AWT components are platform-dependent, which means they are shown in accordance with the operating system’s view. AWT is heavyweight, which means that its components consume resources from the underlying operating system (OS). The java.awt package contains AWT API classes such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List, and so on....

Why AWT is Platform Independent?

The Java AWT utilizes the native platform subroutine to create API components such as TextField, CheckBox, and buttons. This results in a different visual format for these components on different platforms such as Windows, MAC OS, and Unix. The reason for this is that each platform has a distinct view of its native components. AWT directly calls this native subroutine to create the components, resulting in an AWT application resembling a Windows application on Windows OS, and a Mac application on the MAC OS. In simpler terms, the AWT application’s appearance adapts to the platform it is running on....

Java AWT Hierarchy

...

Types of Containers in Java AWT

There are four types of containers in Java AWT:...

Java AWT Tutorial for Beginner & Experienced

Learn the basics of the Abstract Window Toolkit (AWT) in Java, for both beginners and experienced developers....

1. Java AWT Label

Syntax of AWT Label...

2. Java AWT Button

AWT Button is a control component with a label that generates an event when clicked on. Button Class is used for creating a labeled button that is platform-independent....

3. Java AWT TextField

Syntax of AWT TextField:...

4. Java AWT Checkbox

Syntax of AWT Checkbox:...

5. Java AWT CheckboxGroup

CheckboxGroup Class is used to group together a set of Checkbox....

6. Java AWT Choice

The object of the Choice class is used to show a popup menu of choices....

7. Java AWT List

The object of the AWT List class represents a list of text items....

8. Java AWT Canvas

Syntax of AWT Canvas:...

9. AWT Scrollbar

Syntax of AWT Scrollbar:...

10. Java AWT MenuItem & Menu

MenuItem class adds a simple labeled menu item on the menu. The MenuItem class allows you to create individual items that can be added to menus. And Menu is a component used to create a dropdown menu that can contain a list of MenuItem components....

11. Java AWT PopupMenu

Java AWT PopupMenu is a component that is used for dynamically popping up a menu that appears when the user right-clicks or performs any other action on a component....

12. Java AWT Panel

Java AWT Panel is a container class used to hold and organize graphical components in a Java Application....

13. Java AWT Toolkit

Java AWT Toolkit class provides us with a platform-independent way to access various system resources and functionalities. Subclasses of Toolkit are used to bind various components....

Event Handling Components – Java AWT

Here are some of the event handling components in Java:...

1. Java ActionListener

Java ActionListner is a interface which responds to the actions performed by the components like buttons, menu items ,etc....

2. Java MouseListener

Java MouseListner is a interface that responds to the actions performed by mouse events generated by the user. Example: mouse clicks , mouse movements, etc....

3. Java MouseMotionListener

Java MouseMotionListner is a interface which is notified when mouse is moved or dragged....

4. Java ItemListener

Java ItemListner is an interface which handles events related to item selection and deselection those that occur with checkboxes, radio buttons, etc. There is only one Method associated with ItemListner that is itemStateChanged(). This method provides information about the event, i.e. source of the event and the changed state....

5. Java KeyListener

Java KeyListner is an interface in Java notified whenever you change the state of key or can be said for key related events....

6. Java WindowListener

Java WindowListener is a interface used for handling events related to window actions. Events like opening , closing, minimizing, etc are handled using WindowListener....

7. Java Adapter classes

Java adapter classes provide the default implementation of listener interfaces....

8. Close AWT Window

At the end we will need to Close AWT Window, So to perform this task we will use dispose() method. This method releases the resources associated with the window and also removes it from the screen....

Java AWT Examples

Here are some Java AWT examples:...

Java AWT Tutorial – FAQs

1. What is AWT in Java?...

Contact Us