Unit 3: Introducing AWT

5th Semester

3.1 AWT classes

AWT contains large number of classes and methods that allows you to create and manage graphical user interface ( GUI ) applications, such as windows, buttons, scroll bars,etc.  2 packages – java.awt and java.awt.event – are commonly-used.

  1. The java.awt package contains the core AWT graphics classes:
    • GUI Component classes, such as Button, TextField, and Label.
    • GUI Container classes, such as Frame and Panel.
    • Layout managers, such as FlowLayout, BorderLayout and GridLayout.
    • Custom graphics classes, such as Graphics, Color and Font.
  2. The java.awt.event package supports event handling:
    • Event classes, such as ActionEvent, MouseEvent, KeyEvent and WindowEvent,
    • Event Listener Interfaces, such as ActionListener, MouseListener, MouseMotionListener, KeyListener and WindowListener,
    • Event Listener Adapter classes, such as MouseAdapter, KeyAdapter, and WindowAdapter.

 

AWT features include:

  • A rich set of user interface components
  • A robust event handling model
  • Graphics and imaging tools, including space, Color and font classes.
  • Layout managers, for flexible window layouts that don’t depend on a particular window size or screen resolution.
  • Data transfer classes, for cut and paste through the native platform clipboard

Let’s Know in Detail

As you can observe from the above hierarchy, Component is the super class of all Java components and is declared as abstract. That is, we cannot create objects of Component class directly.

  1. Component :- A Component object represents a graphical interactive area displayable on the screen that can be used by the user.Any subclass of a Component class is known as a component. For example, button is a component.
  2. Container :- The Container is a component in AWT that can contain another components like buttons, textfields, labels etc.The commonly-used top-level containers in AWT are Frame, Dialog and Applet.
  3. A component must be kept in a container. You need to identify a container to hold the components. Every container has a method called add(Component c). A container (say c) can invoke c.add(aComponent) to add aComponent into itself. For example,
  4. Window:- The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window.
  5.  Frame :- It  provides the “main window” for your GUI application. It has a title bar (containing an icon, a title, the minimize, maximize/restore-down and close buttons), an optional menu bar, and the content display area.Creating a Frame There are two ways to create a Frame. They are,
    1. By extending Frame class (inheritance)
    2. By creating the object of Frame class (association)

2. By creating the object of Frame class (association)