-1

I was wondering what would be the best/easiest way to render my own graphics over an applet that has been loaded with:

public class Game {

    public static Applet applet = null;
    public static URLClassLoader classLoader = null;

    public static void load() {
        try {
            classLoader = new URLClassLoader(new URL[]{Jar.getJar().toURL()});
            applet = (Applet) classLoader.loadClass("com.funkypool.client.PoolApplet").newInstance();
            applet.setSize(new Dimension(800, 600));
            applet.setBackground(Color.BLACK);
            applet.setStub(new Stub());
            applet.init();
            applet.start();

            JFrame loader = new JFrame("Loader");
            loader.setPreferredSize(applet.getSize());
            loader.add(applet);
            loader.pack();
            loader.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

I would like it to render over the applet, but the applet still maintain all of its original functionality, I believe i would need to use reflection possibly? I was thinking about looking at the way Powerbot.org renders over the runescape client, as the client still maintains all its functionality etc.

If you have any questions or need to see more code, just ask.

  • 1
    do you want to render something "over" applet area or want to modify applet itself? For the first, i would use overlaylayout with jframe and set applet and another panel, and do my mojo on the panel's graphics object. If you wish to modify graphics routine of the applet itself, either modify the applet code or extend from the applet code and override paint method. – Usman Saleem Jan 12 '13 at 22:47
  • I would like it to render over the applet, but the applet still maintain all of its original functionality, I believe i would need to use reflection possibly? I was thinking about looking at the way Powerbot.org renders over the runescape client, as the client still maintains all its functionality etc. – Cory Nelson Jan 12 '13 at 23:05
  • *"would need to use reflection possibly?"* No. Reflection has nothing to do with this. – Andrew Thompson Jan 13 '13 at 06:10
  • For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Jan 13 '13 at 06:14
  • @AndrewThompson I wouldn't be able to post an SSCCE as its a game loader I'm working on for Funkypool.com so i would have to send the entire thing pretty much :/ – Cory Nelson Jan 13 '13 at 06:27
  • I did not ask you to post the code for a *"game loader .. for Funkypool.com"*. I asked you to post an ***SSCCE***. Please pay attention. An SSCCE of this could be made using a much simpler applet, not loaded by `URLClassLoader`, that is an [hybrid application/applet](http://stackoverflow.com/q/12449889/418556). All the applet needs is a few lines of code to add some components to draw on top of. – Andrew Thompson Jan 13 '13 at 06:33

1 Answers1

0

Assuming this draws something (my applet-fu is rusty), then you can draw on top of it by placing it in a JFrame and subclassing the JFrames' void paint(Graphics g) so that it paints whatever it wants to, and then paints something else.

A modified JFrame that does this could be the following (warning: untested code):

public static class OverlayJFrame extends JFrame {
     private JPanel overlay;
     public OverlayJFrame(String title) { super(title); }
     public void setOverlay(JPanel overlay) { this.overlay = overlay; }
     public void paint(Graphics g) { super.paint(g); overlay.setSize(getSize()); overlay.paint(g)); }
}
tucuxi
  • 17,561
  • 2
  • 43
  • 74