How to extend a Java class with a loaded class?
<p>I am injecting a Applet that way that it can't check on which website it is.<br />
The purpose is to load an external unmodified applet into mine so I can embed it into mine.</p>

<pre><code>    final URL[] appletURL = { new URL(Main.getBase() + "/loader.jar") };
    final URLClassLoader classLoader = new URLClassLoader(appletURL); // gets the class
    final Class&lt;?&gt; loader = classLoader.loadClass("loader"); // loads the class
    applet = (Applet) loader.newInstance(); // creates the applet
    applet.setStub(new Injector()); // injects the getdocumentbase, so it thinks he is on his own website
    applet.init(); // start applet
    applet.start();
    applet.setPreferredSize(new Dimension(800, 600)); // to be able to add to jframe properly
</code></pre>

<p>The "applet.setStub(new Injector());" part is to prevent navigating away or not loading because it's not the applet's own website.<br />
But now I want to render the external applet to a screenshot.
I tried this:</p>

<pre><code>@Override
public void actionPerformed(final ActionEvent e) {
    final String s = e.getActionCommand();
    if (s.equals("Screenshot")) {
        final BufferedImage offScreen = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
        applet.update(offScreen.createGraphics());
        try {
            ImageIO.write(offScreen, "PNG", new File("C:/Users/Mitchell/Pictures/screenshot.png"));
        } catch (Exception ex) {  }
    }
}
</code></pre>

<p>But it doesn't use the paint nor updat method.
It uses getGraphics() instead, I got tipped to extend the applet that I want to screenshot.
But the applet is dynamically loaded, so how do I extend a class with a loaded class (or applet)?</p>

<p>Can someone provide a code sample?
I am about to freak out because this is taking all my time and I can't continue without this.</p>
