File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MouseListener error

 
Gabriella Hakansson
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I don't know whats wrong, but when i compile i get the errormessage:
test.java:9: test is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
public class test implements MouseListener{


Do you have to add a box on top of the JLabel for the mouse to click in ? How is that done?

I feel a bit stupid now..
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the section from the Swing tutorial on How to Write a Mouse Listener. You need to implement "all" the methods of the mouse listener, not just one. You only implemented mouseClicked".

Of course the easier solution is to use a JButton and then add an ActionListener to the button. You can use setBorderPainted(false) to make the button look more like a label.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most event listener interfaces have matching abstract classes that have empty body implementations for all methods. For MouseListener that matching class is MouseAdapter. Extending this class instead of implementing MouseListener allows you to implement only a few methods instead of having to implement all of them.
 
Gabriella Hakansson
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! now it works just as it should. I only implemented all the MouseEvents. Thank you both soo much!
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic