Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with ActionListener and JButtons (harder than it first seems

 
Thomas FairBanks
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This program copies the iPhone sort of:

My problem (lines in bold) is that the buttons that I add the ActionListener to are not in the same class as actionPerformed. When I tried to make the JButtons public (outside of the current class), it gave me some exceptions. What can I do to properly add this ActionListener?
[ October 31, 2008: Message edited by: Thomas FairBanks ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best solution for this problem is to use a different ActionListener per Button - then there is no need to call e.getSource at all.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch

Thank you, Ilja; you actually had the patience to read all that code!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:

Thank you, Ilja; you actually had the patience to read all that code!


Didn't. Just read the bold lines.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
Just read the bold lines.


In which case, thank you Thomas FairBanks, for marking the location of the problem.
 
Thomas FairBanks
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, can't believe I didn't think of that. Thanks Ilja
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic