This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes event handling error .. need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "event handling error .. need help " Watch "event handling error .. need help " New topic
Author

event handling error .. need help

abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130


/*

C:\>javac Mouse1.java
Mouse1.java:12: Mouse1 is not abstract and does not override abstract method mou
seReleased(java.awt.event.MouseEvent) in java.awt.event.MouseListener
public class Mouse1 extends Applet implements MouseListener, MouseMotionListener
^
1 error

*/
[/code]
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
Hi Abhay,
Whenever you implement an interface,make sure you satisfy the contract specified by the interface.
The error message clearly states that
mouseReleased(java.awt.event.MouseEvent) method declared in the interface is not implemented in your class.

You can just provide a dummy implementation if you do not wish to handle the mousereleased event.
public void mouseReleased(java.awt.event.MouseEvent e)
{
`
}

Thanks
Yogi
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130


You can just provide a dummy implementation if you do not wish to handle the mousereleased event.
public void mouseReleased(java.awt.event.MouseEvent e)
{
`
}

Thanks
Yogi



thanks yogi ,
it works after one more .....mousePressed event , so we can say that it was necessary to put that dummy code because we implemented related interfaces .. right ?? or there is another reason behind it ??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

If a class implements an interface it must implement all methods of that interface. In those cases you don't want to, you must provide skeleton implementations - empty bodies where void is returned, and returning some constant where a return value is required.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: event handling error .. need help
 
jQuery in Action, 3rd edition