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)