Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener as a parameter for a constructor

 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a class (PlayButtonPanel) whose constructor has only one parameter, which is an ActionListener object. That's because I want my PlayButtonPanel objects to be created and used by different objects, although all of them must implement ActionListener. I created two other classes, both implementing ActionListener and calling new PlayButtonPanel(this). One of these classes works, but the other gives me a compile time error saying there is no constructor PlayButtonPanel(ClassName). Does anyone have a clue about what's wrong? Do a class have to do anything besides implementing ActionListener and having the actionPerformed method for it to work?
Thanks
Leonardo
 
Steve Lovelace
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing any code, can only guess that in the case of this one class you forgot to putimplements ActionListener in its class statement.
 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code works

This one doesn't
 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My constructor is like that:
 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found out the problem, I was compiling that stuff with an older PlayButtonPanel.class instead of compiling the new PlayButtonPanel.java. "make clean" solved the problem. Sorry if I made anybody waste time with that.
 
Steve Lovelace
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a waste. It's useful to be reminded that backlevel code can be the cause of a mysterious bug.
[ September 30, 2003: Message edited by: Steve Lovelace ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic