I have an applet running in a browser tab. When I switch to a different tab in the same browser, or ALT-TAB to another application entirely, the applet loses focus. When I retur
I believe java has the requestFocus() method. It's in the Component class, so your JPanel or whatever you are using may be able to use this.
requestFocus()
For the javascript part, this is what a quick googling reveals: http://www.raditha.com/java/javascript.php. I hope it helps you!