Part 8 | Creating one ActionListener for Multiple Buttons using ActionEvent | Java GUI Tutorial

preview_player
Показать описание
In this part, we will edit the event handler code so that we only use one event listener object for both of our JButton components. In the actionPerformed method, we will make use of if statements and the getSource() method of the ActionEvent object so that the program can figure out which button was clicked and respond accordingly: print beep if button1, print boop if button2.

#Java #ActionEvent #JavaSwing
Рекомендации по теме
Комментарии
Автор

Bro you are a life saver I was looking for how to create multiple buttons I CANT FIND ANYONE BUT YOU. YOU HELPED ME A LOT I CANT THANKS TOU ENOUGH

RajeshKumar-hrym
Автор

Thanks, I was looking particularly for this thing

achalsharma
Автор

Thank you for the help also can you use switch case instead of if else?

Weebmaster
Автор

I thought you couldn't make objects out of interfaces

aquarius
Автор

Well that, matches a type writer, net hack! Interface! Reversed fx = dx-- dx = fx! But it, must = legally!

paulhetherington