0

In a Java applet-application, is there a way to obtain the actual applet instance somehow? e.g. a static method or singleton that makes this available? I'm working on a project where I can't access/modify the Applet class source code so I need a way to find the current Applet instance.

The reason for this is I think I need to inspect/modify how the applet is loading resources.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • Clearly, it's a Java question... – Mr. Boy Sep 25 '13 at 12:05
  • As you alluded to yourself, not helping when you have an answer hurts the site as a whole because anyone else finding this question would be mislead. Think about _that_ next time the medium of writing comments leads to crossed wires! – Mr. Boy Oct 01 '13 at 13:16
  • if you have access to an AWT/Swing component that gets added to the hierarchy you can iterate parents until you find a parent that is instanceof Applet. otherwise I think you are out of luck. does this answer your question? – Omry Yadan Oct 01 '13 at 14:05

1 Answers1

1
import java.applet.*;
import java.awt.*;

public class DrawingApplet extends Applet {

   private static Applet INSTANCE;

   public void init() {
      INSTANCE = this;
      // your init logic goes here;
      ....
   }

   public void paint( Graphics g ) {
     // your paint logic goes here.
   }
}

Why this way won't work for you?

UPDATE 1 If you don't have the access to your Applet sources, I'm afraid you can't catch the instance of the applet. More details are explained in this thread: Getting all instances of a class

Community
  • 1
  • 1
Archer
  • 5,073
  • 8
  • 50
  • 96