I am trying to do some form of field validation. Basically I have say 5 JTextFields on a form and when a user completes a field and it loses the focus I want it to validate the entry and if the entry is correct or incorrect indicate that with a visual indication (I used a plus and a cross icon to indicate this)
I was trying to simply this sort of thing:
aptjf.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e){
met1();
}
public void focusLost(FocusEvent e){
met2();
}
});
aptjf2.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e){
met3();
}
public void focusLost(FocusEvent e){
met4();
}
});
aptjf4.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e){
met5();
}
public void focusLost(FocusEvent e){
met6();
}
});
to something a little cleaner liike
addMyFocusLister(NameOfTextField, MethodIfFocusGained, MethodIfFocusLost);
Or is this just not possible?