Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

Event Adapters

There are some event listeners that have multiple methods to implement. That is some of the listener interfaces contain more than one method.

Ads

Event Adapters

     

There are some event listeners that have multiple methods to implement. That is some of the listener interfaces contain more than one method. For instance, the MouseListener interface contains five methods such as mouseClicked, mousePressed, mouseReleased etc. If you want to use only one method out of these then also you will have to implement all of them. Thus, the methods which you do not want to care about can have empty bodies. To avoid such thing, we have adapter class. 

Adapter classes help us in avoiding the implementation of the empty method bodies. Generally an adapter class is there for each listener interface having more than one method. For instance, the MouseAdapter class implements the MouseListener interface. An adapter class can be used by creating a subclass of it and then overriding the methods which are of use only. Hence avoiding the implementation of all the methods of the listener interface. The following example shows the implementation of a listener interface directly. 

public class MyClass implements MouseListener {
...
someObject.addMouseListener(this);
...

/* Empty method definition. */
public void mouseEntered(MouseEvent e) {
}

/* Empty method definition. */
public void mouseExited(MouseEvent e) {
}

/* Empty method definition. */
public void mousePressed(MouseEvent e) {
}

}
}

 

Advertisements

Share on Google+Share on Google+

Event Adapters

Posted on: December 17, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Event Adapters  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
muhammed younus attari
March 28, 2011
i like it

i like this website, it helped me allot but the thing is if it provides examples then it will be more good.
deepak kumar sana
January 23, 2013
core java

something ??????????????

Ads

 

Ads