ComponentEvent in Java

An event of this type serves as notification that the source Component has been moved, resized, shown, or hidden. Note that this event is a notification only: the AWT handles these Component operations internally, and the recipient of the event needs to take no action itself.

getComponent() returns the component that was moved, resized, shown or hidden. It is simply a convenient alternative to getSource().

getID() returns one of four COMPONENT_ constants to indicate what operation was performed on the Component.

Component events are generated when a component is shown, hidden, moved, or resized. AWT automatically deals with component moves and resizing; these events are provided only for notification.

Subclasses of ComponentEvent deal with other specific component-level events.

The class structure for ComponentEvent is given as

public class java.awt.event.ComponentEvent extends java.awt.AWTEvent{
// Public Constructor
public ComponentEvent(Component source, int id);
// Constants
public static final int COMPONENT_FIRST;
public static final int COMPONENT_HIDDEN;
public static final int COMPONENT_LAST;
public static final int COMPONENT_MOVED;
public static final int COMPONENT_RESIZED;
public static final int COMPONENT_SHOWN;
// Public Instance Methods
public Component getComponent();
public String paramString(); // Overrides AWTEvent
}

The details of the class structure are given as follows:

public final static int COMPONENT_FIRST;

public final static int COMPONENT_FIRST represents a conatant that specifies the beginning range of component event ID values.

public final static int COMPONENT_HIDDEN;

public final static int COMPONENT_HIDDEN represents a conatant that is an Event type ID indicating that the component was hidden.

public final static int COMPONENT_LAST;

public final static int COMPONENT_LAST represents a conatant that specifies the ending range of component event ID values.

public final static int COMPONENT_MOVED;

public final static int COMPONENT_MOVED represents a conatant that shows an Event type ID indicating that the component was moved.

public final static int COMPONENT_RESIZED;

public final static int COMPONENT_RESIZED represents a conatant that shows an Event type ID indicating that the component was resized.

public final static int COMPONENT_SHOWN;

public final static int COMPONENT_SHOWN represents a conatant that shows an Event type ID indicating that the component was shown.

public ComponentEvent (Component source, int id);

public ComponentEvent (Component source, int id) constructs a ComponentEvent with the given characteristics.

Parameter
source – The object that generated the event.
id – The event type ID of the event.

public Component getComponent();

public Component getComponent() method returns the source of this event.

This method returns the source of this event.

public String paramString();

public String paramString() method is a helper method for toString() to generate string of current settings.

This method returns a String with current settings of the ComponentEvent.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on [email protected]

Write A Comment