• 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

those crazy listeners!

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a class MyPanel that extends jpanel but implements ActionListener, so i can just add itself to components i throw into MyPanel, and it worked fine but here is where my problem is :
a certain button adds another custom component(that also has a button), so in the actionPerformed method im trying to add an actionListener(itself) to it, but the compiler doesnt like this at all and i get an error "cannot find symbol: method addActionListener(MyPanel)"
is it that you cant add an actionListener from within the actionListener you want to add? whats going on here?
earlier in the code(outside of the actionListener) i can call button.addActionListener(this) just fine, but i cant figure out why this is wrong here.
thanks for any help!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The listener (which is a regular class, even if it doesn't look that way) does not have a method addActionListener. You need to invoke it with the object that you want it attached to, e.g. myPanel.addActionListener.
 
Micah Pezdirtz
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yea i found out my problem didnt have to do with that, it was that the method i was using to get the JButton from the other component was returning the jbutton, casted as a Component(and apparently that is what has no addActionListener() method. the method returning the component(which happened to be the jbutton) was supposed to also be usful for returning other types of components from out of an arraylist, which is why they were being casted as Components. turns out i only really need to be able to get the JButton, and never any other components....so i just changed it so its not casting as a Component... silly mistake...
reply
    Bookmark Topic Watch Topic
  • New Topic