Of course you can for Swing but I'm not sure if it's possible for applets.Note that such solution is most likely to be OS specific.I don't know how to do it under UNIX but under Windows you need to hook WndProc function and listen for WM_DEVICECHANGE.I've done it several times using C++ and MFC.More information is available here.
[^]