?
Solved

about mouseAdaptor

Posted on 2004-04-19
7
Medium Priority
?
252 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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