I have a Component which I am using both in a standalone Java application as well as in a Java applet. How can I figure out from within the Component whether my component is in an applet?
Also, once I figure out that I’m running in an Applet, how can I get access to the Applet?
I think you should be able to do it by repeatedly calling
Component.getParent()until you get to the top of the container tree, and then checking whether that container is aninstanceof Applet.The code below is completely untested: