Skip to content
Advertisement

How to make a Java AWT Action Listener run multiple times

I have this code and I’m trying to have one action listener be used, and it be used multiple times. I have tested this code over and over again, and I have figured out that it is only running actionPerformed one time (When you click the “Login” button)

JavaScript

Is there a way that I can fix this so that I can repeatedly use the actionPerformed method? I have tried doing different ways of making Action Listeners but I can’t seem to get them right (they return errors.)

Advertisement

Answer

it is only running actionPerformed one time (When you click the “Login” button)

JavaScript

You only ever add it to the “loginButton”.

You need to add it to your other buttons as well.

However, it is NOT a good design to share an ActionListener. A listener should only perform an single function.

I have tried doing different ways of making Action Listeners

Yes, creating a unique ActionListener for each button is the better approach.

for example:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement