1. Add a FocusListener to the JTextField. On focusGained you save the current value. On focusLost you reset the text field with the saved value.
2) Add an ActionListener to the text field. When the ActionEvent fires you get the current value and update the saved valued.
However this sounds like a strange requirement. Maybe
you should be displaying a JOptionPane asking the user to enter a value. Then if the user hits OK on the option pane you save the value otherwise you ignore the value.