HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

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

30,716 views November 26, 2019 8:11

Watch on YouTube
Channelchoobtorials

Description from the creator

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 GUI Playlist: youtube.com/playlist?list=PLWfJeLqH0KUUicazPYhT…

Python for Beginners Playlist: youtube.com/playlist?list=PLWfJeLqH0KUWyXsYJ4NT…

Twitter: twitter.com/choobtorials

#Java #ActionEvent #JavaSwing

About this tutorial

choobtorials published this 8:11 video tutorial on November 26, 2019. It has been watched 30,716 times on YouTube.

Category
Education
Duration
8:11
Published
November 26, 2019
Views
30,716
Likes
288

Tags

Share

Further reading

  • java - One action listener, two JButtons - Stack Overflow stackoverflow.com

    Define one ActionListener class. Declare an object of the action class in the UI class. Set each button actionListener using addActionListener method and add this action class reference as param and finally set action c…

  • How to add multiple ActionListeners for multiple buttons in ... stackoverflow.com

    You just need to create new instance of the ActionListener each time. BTW for lots of reasons it is recommended to use Action's instead. Here is nice resource which also explains why you should go with using Actions ove…

  • java - How to add action listener that listens to multiple ... stackoverflow.com

    I'm trying to figure out what i am doing wrong with action listeners. I'm following multiple tutorials and yet netbeans and eclipse are giving me errors when im trying to use an action listener. ...

  • java - One action listener for multiple JButtons? | DaniWeb daniweb.com

    how to create a table in database by using java 14 ; java gui/arraylist help! 6 ; Simple application with multiple windows - Java 5 ; help for buttons in java 6 ; Java Swing, MouseMotionListener troubles 10 ; find key w…

  • Java ActionListener - javatpoint javatpoint.com

    Java ActionListener Interface. The Java ActionListener is notified whenever you click on the button or menu item. It is notified against ActionEvent. The ActionListener interface is found in java.awt.event package. It h…

This tutorial in other languages