Introduction To AWT

  • AWT stands for Abstract Windowing Toolkit. It is a package in Java that provides support for building GUI.
  • The name of the package is java.awt.
  • The API of the AWT package consists of a collection of classes and methods that enables you to design and manage the Graphical User Interface (GUI) applications.
  • The AWT package supports applets, which help in creating containers, such as frames or panels that run in the GUI environment.
  • Building applications with graphical user interfaces are easily broken into two parts.

AWT Components

  • Labels:
    Labels provide user prompts, and for displaying information that should not be modified by users
    Label l=new Label(“Name”);
  • Button
    This is the component of Java Abstract Window Toolkit and is used to trigger actions and other events required for your application.
    Button button=new Button(“Click”);
  • Checkbox
    This component allows the user to change the state of the component
    Checkbox Checkbox=new Checkbox(“OptionalCheckbox1”);
  • Radiobutton
    This is the special case of the Checkbox component of Java AWT package. This is used as a group of checkboxes which group name is same.
    Only one Checkbox from a Checkbox Group can be selected at a time.
    CheckboxGroup cbg=new CheckboxGroup();
    Checkbox radiobutton1=new Checkbox(“One”,cbg,false);
    Checkbox radiobutton2=new Checkbox(“Two”,cbg,false);
  • TextArea
    This is the text container component of Java AWT package.
    This component can contain multiple lines.
    TextArea ta=new TextArea(20,5);
  • TextField
    This is also the text container component of Java AWT package. This component contains single line and limited text information.
    TextField tf=new TextField(20);

Example of the AWT Components :

Output of the Example:

Output of the Example

Events in AWT :

  • An event describes, in sufficient detail, a particular user action.
  • There are many types of events that are generated by an AWT Application.
  • These events are used to make the application more effective and efficient.
Types of AWT Events :

Types of AWT Events

AWT Event:

  • ActionEvent:
    It indicates the component-defined events occurred i.e. the event generated by the component like Button, Checkboxes etc..
  • MouseEvent:
    The MouseEvent class handle all events generated during the mouse operation for the object. That contains the information whether a mouse is clicked or not if clicked then checks the pressed key is left or right.
  • WindowEvent :
    If the window or the frame of your application is changed (Opened, closed, activated, deactivated or any other events are generated), WindowEvent is generated.
  • FocusEvent:
    This class indicates the focus where the focus has gained or lost by the object.
  • TextEvent:
    TextEvent is generated when the text of the object is changed.
  • KeyEvent:
    The KeyEvent class handles all the indication related to the key operation in the application if you press any key for any purposes of the object then the generated event gives the information about the pressed key.

Event Dispatching:

Consider the Following

Event Dispatching



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.