Skip to content
Advertisement

How to trigger another action listener after completion of ActionListener?

I created a GUI with a JFrame, JPanel, JLabel and a JButton.

JavaScript

I added the button and the label to the panel. I added two ActionListeners for the button.

JavaScript

I want to execute the first action listener. Then execute the other one. Basically, I have some text that I want to output in the label, sequentially. I want for it to show “Hello” then “Goodbye” on the panel. The problem that it is giving me, is that it only shows the text from my second ActionListener “Goodbye”.

Advertisement

Answer

You can convert second one to the below sample. The reason it only show the second one because both runs immediately and you see the last one as label.

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