Set window close (x) to use the endApplication function and update GUI