Solved

about mouseAdaptor

Posted on 2004-04-19
7
201 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:
mayankeagle 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:mayankeagle
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:mayankeagle
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now