3

I have a text field where I have imposed some constraint in input data, by the help of InputVerifier. The constraint is if the text field is left empty, then an error message will pop up. When the application starts, the cursor remains on the text field (text_field.requestFocusInWindow()).

Now, If the exit button is clicked, at anytime, The application should terminate immediately. But if the text field remains empty, it displays the error message and doesn't exit. How to solve this problem?

Exit Code:

dispose();
System.exit(0);
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
singha
  • 3,351
  • 3
  • 13
  • 4

1 Answers1

0

Ok, let's say your textfield is in a JFrame. Then register a WindowEventListener on the frame. Catch the event that closes the window and remove the InputVerifiers from all textfields. Then call System.exit().

alexkelbo
  • 724
  • 6
  • 18