There are two ways to handle generated events:
A) You will create single general actionPerformed() method which can be encapsulated in event handler as you tried and then with you of loop and if statement try to figure out which event was triggered. This approach makes your code short as you do not have to repeat some lines over and over. Unfortunately with number of events attached to this approach you are running risk of making mistake in event recognition and spending long time checking out if the logic inside is working as you expect.
B) Do it the way as showed in my code by providing actionPerformed() to every object that need it. By doing so you code will be longer as some code will be repeated. However when some action doesn't work as you intended you just go to specific section of code and check out "what the hell is going on!"
Consider what is better for you, as you can see I prefer option B for its easy debugging.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
Offline 6,659 posts
since Dec 2004