answersLogoWhite

0


Best Answer

An Adapter class is just a "blank" implementation of a Listener interface. They're convenience classes made so you don't need to implement all of the methods of an interface.

A good example is the MouseListener interface. Let's say you want to detect when a user clicks on your Component. You only need to implement the mouseClicked method to get that part working. This will leave you with...

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

...at the end of your implementation. Ugly. So Java gives us the MouseAdapter class (which gives us the same empty implementations as above). We can use this in place of a MouseListener to try to keep our code cleaner.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

When using a listener you have to implement all the methods that the class provides. An adapter has already implemented empty methods and you can only implement those you need. It is mostly quality of life.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is difference between Adapter class and listeners in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What's the difference between the Class 365 and Class 465 466?

The difference between the Class 365 and Class 465, 466 is basically the cost.


Difference between exclusive or inclusive class intervals?

difference between inclusive and exclusive class interval


What is difference between first class and second class on train trips?

What is the difference between buying a 1st class and a 2nd class ticket on the train in England?


What is the difference between a class What is the difference between a class III and class IV hitch and?

class III rated for up to 5,000lbs, class IV is rated for up to 10,000lbs towing capacity


Can you use a 15 volt dc adapter to run a 12 volt portable DVD player The adapter in question lists as a class 2 transformer if that makes any difference?

No. You should use the adapter specified for the DVD player. Using the wrong adapter can damage the DVD player and/or the adapter and/or cause a fire.


What is the difference between abstract class and final class?

20


Difference between Mercedes e class elegance and classic?

What is the difference between Mercedes Benz E class 'Elegance'and classic


What is the difference between classes of IP addresses?

difference between ip address and class


What do you mean by object adapter explain with an example?

The adapter method is when you create a class which wraps around another (holding that other class as a variable). The adapter class then responds to calls by calling the methods of the held variable.


What is the difference between a first class and a second class lever?

thanks


Difference between class 1 and class 2 preservatives?

znd


What is the difference between class intervals and class width in statistics?

NONE