When you push the 'X' of a JFrame, this generates a WindowEvent, which is sent to any WindowListeners you have attached to the JFrame (and the windowClosing/windowClosed method of the listener is called).
Applets/JApplets have lifecycle events in the Applet class to handle things like navigating away from the page, the applet being destroyed, etc. applet.destroy() is probably analogous to pressing the 'X' to close an application - however, it's probably better to create a socket in start() and release/destroy it in stop() - this means that the applet won't hang onto the socket while it's not 'active' (i.e. the use has navigated away from the page the applet is on).
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.