Is there neater/simpler way of executing if-then-else statements using a listener's getSource()?
I've got a FocusListener that I need to highlight the text in the JTextField that triggered the FocusListener
private class calculator implements FocusListener{
public void focusGained(FocusEvent evt) {
if(evt.getSource()==txtInitialRead ){
txtInitialRead.selectAll();
}
My problem is that I have quite a lot of JTextFields and would need to create an if statement in the FocusListener for each one. Is there any easy method of doing this? Switch branches do not work for this object type.
Of course this isn't a huge deal, I just think there must be a neater way to do this.
Thanks!