JavaRanch » Java Forums »
Java »
Swing / AWT / SWT
| Author |
Problem with ActionListener and JButtons (harder than it first seems
|
Thomas FairBanks
Greenhorn
Joined: Oct 31, 2008
Posts: 2
|
|
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
Joined: Jul 11, 2001
Posts: 14112
|
|
|
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.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
And welcome to JavaRanch Thank you, Ilja; you actually had the patience to read all that code!
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
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
Joined: Oct 13, 2005
Posts: 32712
|
|
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
Joined: Oct 31, 2008
Posts: 2
|
|
|
Wow, can't believe I didn't think of that. Thanks Ilja
|
 |
 |
|
|
subject: Problem with ActionListener and JButtons (harder than it first seems
|
|
|
|