Fields inherited from class java.awt.AWTEvent. Changed - the Component at the top of the hierarchy which was changed changedParent - the parent of changed. This may be the parent before or after the change, depending on the type of change. ChangeFlags - a bitmask which. The ultimate super class of all the GUI components both in AWT as well as Swing is the java.awt.Component. An immediate sub-class of it is the Container class. So every container is a component (from inheritance). Before learning the hierarchy, let us see what is a component and a container. Let’s look at each of these classes now. At the top of the AWT hierarchy is the Component class. Component is an abstract class that encapsulates all of the attributes of a visual component. Except for menus, all user interface elements that are displayed on the screen and that interact with the user are.

After having the basic idea of GUI, let us know how many Java AWT Components classes exist with java.awt package. This knowledge is essential to go further in the tutorial.

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.

Following is the class signature

public abstract class Component extends Object implements ImageObserver, MenuContainer, Serializable

Properties of Java AWT Components
The Class At The Top Of The Awt Hierarchy Is
  1. A Component object represents a graphical interactive area displayable on the screen that can be used by the user.
  2. Any subclass of a Component class is known as a component. For example, button is a component.
  3. Only components can be added to a container, like frame.
The Class At The Top Of The Awt Hierarchy Is
Important methods of Component class

The Class At The Top Of The Awt Hierarchy Is Component

Following are the important methods, practiced very often, of Component class that can be used by all the sub classes (components).

Which Class Is At The Top Of The Awt Event Hierarchy

  1. setEnabled(boolean): The parameter false makes the component disabled so that it does not respond to user interactions (say, clicks).
  2. setBounds(): Using this method, the programmer can give his own size to the component in terms of width and height and also the location where he can place the component in the container. This method is not used often as the programmer prefers to place the component in the container using layout managers.
  3. getWidth(): The programmer can obtain the width of the component.
  4. getHeight(): The programmer can obtain the height of the component.
  5. paint(): Used very extensively to draw graphics. This method is called implicitly when the frame is created or resized.
  6. repaint(): Used by the programmer to call the paint() method explicitly anywhere in the program.
  7. setBackground(): Used to give a background color to a component.
  8. setForeground(): Used to give a foreground color to a component.
  9. setFont(): Used to give a font to a component to display the text.
  10. getSize(): Returns the size of the component.
  11. setSize(): Used to give the size to the component.
  12. update(): The is method is called implicitly by the repaint(). A call to this method clears the earlier drawings existing on the container.