Devi associare un WindowListener (o windowAdapter) al frame e gestire i metodi relativi alla chiusura.