Singlets are evil, what do you expect ?;)
Perhaps the most complete approach would be to load most of the applet into another classloader (use java.net.URLClassLoader.newInstance). Then use WeakHashMap to associate the class loader with the applet. If you could divide most of the code into a regular classloader (as the parent of each classloader for an applet) and into the normal applet codebase, this would be faster, but more work.
Other hacks:
If you have access to any component, you can reuse Component.getParent or SwingUtilities.getRoot.
If you are in the instance stream for each applet, then you can configure ThreadLocal.
From EDT you can read the current event from the queue (java.awt.EventQueue.getCurrentEvent ()) and possibly find the component from this. Alternatively, click EventQueue with the dispatchEvent method overridden.
Tom Hawtin - tackline
source share