EventObject Class in Java

EventObject class in Java

Eventobject serves as a superclass for all events objects used by the Java AWT event model and the JavaBeans event model. This class defines a very generic type of event; it is extended by the more specific event classes in the java.awt, java.awt.event, and java.beans packages.

The class is named EventObject to avoid confusion with java.awt.Event, which was used to represent events in the old Java 1.0 event model.

The only common feature shared by all events is a source object, which is the object that in some way “generated” the event. The source object is passed to the EventObject() constructor, and is returned by the getsource() method.

The Class Structure of the EventObject is given as

public class java.util.EventObject extends java.lang.Object implements java.io.Serializable {
// Public Constructor
public Eventobject(Object source);
// Protected Instance Variables
protected transient Object source;
// Public Instance Methods
public Object getSource();
public String toString();// Overrides Object

The details of the class structure are given as follows:

protected transient Object source;

protected transient Object source represents the object that generated this EventObject.

public EventObject(Object source);

public EventObject(Object source) constructor creates an EventObject whose source is the given object.

source – The object that generated this EventObject.

public Object getSource();

public Object getSource() method returns the object that is the source of this EventObject.

This method returns the object that generated this EventObject.

public String toString();

public String toString() method returns a string representation of this EventObject.

See also  How To Communicate Between Two Machines Using UDP in Java

This method returns a string that represents this EventObject.

Apart from these EventObject class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals()
  • getClass()
  • notify()
  • wait(long)

Share and Enjoy !

Leave a Reply

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