lundi 24 juillet 2017

Smoother way to check attribute for several states

I recently tumbled about something from which I think there should be a smoother way, but I couldn't find one.

In one of my methods I have to check where exactly the ActionEvent e comes from. Since I have multiple buttons which should call the same method upon clicking, I checked for them like this:

if (e.getSource() == btn1 || e.getSource() == btn2 || e.getSource() == btn3)

for me this does not look that nice, because I have to call e.getSource()for every button. I thought there should be something like:

if(e.getSource() == btn1 || btn2 || btn3)

I know this does not work, but I hope you get the concept of what I want to achieve. If its a duplicate, I am sorry, but I couldn't find it. If its not possible at all, then I'll have to live with it.

Aucun commentaire:

Enregistrer un commentaire