A Robot is not part of the GUI. It does not execute on the Event Dispatch Thread, so closing the GUI has no effect on it.
How this be resolved?
Add logic in your windowClosing(...)
method to stop the Robot. So you will need to somehow restructure your code to get rid the while (true)
loop.
Maybe you can create an ArrayList to keep track of all the events you want to generate. Then you can use a Timer to invoke each event. Then in the windowClosing() code you stop the Timer.