public void focusLost(FocusEvent e){
  try {
    int n=Integer.parseInt(getText());
    setValue(n);
  }
 catch (  NumberFormatException e1) {
    setText(Integer.toString(getValue()));
  }
}

public void focusLost ( FocusEvent e ) { try { int n = Integer . parseInt ( getText ( ) ) ; setValue ( n ) ; } catch ( NumberFormatException e1 ) { setText ( Integer . toString ( getValue ( ) ) ) ; } }
if focus is lost , attempt to store the text value being displayed as int ; if this cannot be done , restore the previous value .
