• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

adding listeners

 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic