Solved

about mouseAdaptor

Posted on 2004-04-19
7
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

717 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