Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Handle multiple events with one function?

First of all, I am a complete Java NOOB.

I want to handle multiple button presses with one function, and do certain things depending on which button was clicked. I am using Netbeans, and I added an event with a binding function. That function is sent an ActionEvent by default.

How do I get the object that was clicked in order to trigger the binding function from within that function so I know which functionality to pursue?

like image 585
Logan Serman Avatar asked Jul 05 '26 06:07

Logan Serman


1 Answers

The object that sent the event is the event source so evt.getSource() will get you that. However, it would be far better to have separate handlers for separate events.

like image 152
Draemon Avatar answered Jul 07 '26 18:07

Draemon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!