ComponentEvent, ContainerEvent class in java.awt.event package: Integer constants, Constructor, Methods

ComponentEvent class: ComponentEvent class handles events created when a component is moved, re-sized, hidden, or when it becomes visible.

Integer constants defined by ComponentEvent class:

  • COMPONENT_MOVED: When component was moved.
  • COMPONENT_RESIZED: When component was resized.
  • COMPONENT_HIDDEN: When component was hidden.
  • COMPONENT_SHOWN: When component becomes visible.

Constructor defined by ComponentEvent class:

ComponentEvent(Component src, int type)

Method defined by ComponentEvent class:

getComponent( ) method: It returns component that created the event.


Component getComponent( )

ContainerEvent class: ContainerEvent Class handles events created when component is added or removed from a container. It is a sub class of ComponentEvent class.

Integer constants defined by ContainerEvent class:

  • COMPONENT_ADDED: When a component is added.
  • COMPONENT_REMOVED: When a component is removed.

Constructor defined by ContainerEvent class:

ContainerEvent(Component src, int type, Component com)

Methods defined by ComponentEvent class:

getContainer( ) method: It is used to get reference to container which created event.


Container getContainer( )

getChild( ) method: It is used to get reference to component which was added or removed from container.


Component getChild( )

Leave a Reply