• Post Reply Bookmark Topic Watch Topic
  • New Topic

adding listeners  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with adding two listener types. My code is as follows.

class MyListeners implements KeyListener, MouseMotionListener
{
// all methods for both interfaces are //included
}

This class compiles fine. In another class I have this code :

JInternalFrame jif = a valid frame;
jif.addKeyListener(new MyListeners());
jif.addMouseMotionListener(new MyListeners());
This piece of code errors when I try to compile. It's having problems with adding the MouseMotionListener because if I comment out that line it works just fine.
Can anybody give any insight into what the problem is? The actual compiler error says the Component cannot be applied to MyListeners. Is there a problem adding MouseMotionListeners to JInternalFrames?
Many thanks.
Paul
 
Bill Prentice
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm probably wrong but don't you have to set the content pane and add all your bits to that and then attach the listeners. As an alternative you could extend MouseMotionAdaptor rather than implement MouseMotionListener.
 
mick barry
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you've posted looks fine. Maybe double check your import's.
If you can post the offending source file it may give more clues.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!