[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

about mouseAdaptor

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
tom_mk
Asked:
tom_mk
  • 3
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
Yes, you can provide the implementation only for those methods which you want.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
mmuruganandamCommented:
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
 
zzynxSoftware engineerCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now