Solved

about mouseAdaptor

Posted on 2004-04-19
7
224 Views
Last Modified: 2010-03-31
is it true that .. i don't reaaly needto implement all the mouse function for mouse adaptor
b/c it already implements all required interfaces and we can just extend only the methods we want.

for ex..

b1.addMouseListener(new MouseAdapter()
{
public void MouseEntered(MouseEvent e)
{
b1.setBackground(Color.BLUE);
}
public void MouseExited(MouseEvent e)
{
b1.setBackground(Color.YELLOW);
}
});


Thxx
Tom
0
Comment
Question by:tom_mk
  • 3
7 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 total points
ID: 10857961
Yes, you can provide the implementation only for those methods which you want.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10857972
Instead of using an anonymous inner-class, based on your requirements, you can also make a sub-class of MouseAdapter which implements only those methods that are needed - and use an object of that class as a mouse-listener.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10857982
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10857984
Adapter is a design pattern.  This MouseAdapter is also belongs to that category.

Since, it has a dummy implementation of all the methods, you don't  really need to implement all the method.
Whatever method you want, you can override that method.  That is enough.

So it is hiding the complexity of the "implement all" strategy forced by the interface.

That is how it is useful as adapter.


Regards,
Muruga
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10858002
Yes, it is true.
MouseAdapter is an implementation of MouseListener.
But the implementation are just empty functions.
You just have to overwrite the functions that you want.

In the words of the java help:
"
   public abstract class MouseAdapter extends Object implements MouseListener

   An abstract adapter class for receiving mouse events. The methods in this class are empty.
   This class exists as convenience for creating listener objects.
"

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question