AWT in java

AWT (Abstract Window Toolkit)

AWT (Abstract Window Toolkit) represent a class library to develop application using GUI. The java.awt package got classes and interfaces to develop GUI and let this users interact in a more friendly way with the applications.

Classes of AWT



A component represent an object which is displayed pictorially on the screen. A component is a graphical representation of an object on the screen.

Useful methods of component class
void add(Component c)
inserts a component on this component

void setSize(int width,int height)
Resize the component so that it has new width and height as passed to setSize() method.

void setVisible(boolean b)
Shows or hide the component depending on the value of parameter b. setVisible(true) will  display the component to function and setVisible(false) will disable it.

Font getFont()
It returns the font of the component.

void setFont(Font f)
It sets a particular font f for the text of the component.

Color getForeground()
It gives the foreground color of the component.

void setForeground(Color c)
It sets a foreground color c to the component.

Color getBackground()
It gets the backgrund color of the component.

void setBackground(Color c)
It sets backgroud color c for the component.

String getName()
It returns the name of the component.

void setName(String name)
It sets a new name for the component.

void setBounds(int x, int y, int w, int h)
It allots a rectangular area starting at (x, y) coordinates and with width w and height h. The component is resized to this area before its display.


  • It is subclass of Component
  • Container contains additional methods that allow other component objects to be nested
  • It allow multilevel containment system
  • Container is responsible for “laying out” any components that it contains


  • Panel is a window that does not contain a border, title bar or menu bar Applet viewer provides these items
  • It is a concrete subclass of Container
  • It implements container
  • It is super class for Applet
  • When a stream o/p is directed to an applet, it is drawn on the surface of a “panel object”
  • Components can be added to Panel object by its add() method
  • setLocation(), setSize(), setBounds(), allows components to be positioned


  • This class creates a top level window which is not contained within any object- it sits directly on the desktop
  • Not usually used to create windows but it’s subclasses
  • Frame is used to create windows


  • Subclass of Window- Used to create “windows”
  • Has a title bar, menu bar, borders & resizing corners
  • When a Frame object is created within an applet, a warning message is displayed (such as Java Applet Window)
  • When a Frame object is created by a program, a normal window is created

Canvas, Graphics, Color, Font, Image

 Not a part of hierarchy for applet or frame window
 Useful to create a blank window upon which user can draw graphics
 Used for painting basic shapes
 Used for creating, getting & setting colors
 Represents a Font
 Represents an image with methods for image handling



Leave a Reply

Your email address will not be published. Required fields are marked *