user1432617
user1432617

Reputation: 11

Take a "screenshot" of 3rd party applet in my webpage

I have a third party Java applet that I am going to embed in my webpage but I don't have access to the applet code.

But I want to create a button on my page on clicking which will create a screenshot of the applet (but not the whole screen). I tried using the Robot class but that would take the whole screen which I don't want

BufferedImage screencapture = new Robot().createScreenCapture(
    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );

I was looking over the net and found code but those require access to the applet which I don't have.

Is it possible to do it using java? If so, how?

Upvotes: 0

Views: 461

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168815

I see at least two options.

2nd applet

  • Use a 2nd applet to get a reference to the applet, using AppletContext.getApplet(name).
  • Call Applet.getLocationOnScreen() for the co-ordinates.
  • It is your page, so unless the applet size is set using percentages, you know the width x height to capture.
  • Either use sockets to connect to the desktop/CLI app. that takes the screen-shot, or use the applet to take the screen-shot. Either way, it will require the applet to be trusted.

Extend the applet

Extend the original applet & add a new method to return or export an image of the current applet surface. See ComponentImageCapture.java for an example.

Options for exporting the image:

  • Deploy the applet using JWS - use the JNLP file API to export the image to the local file-system.
  • Digitally sign the applet export the image to the local file-system using the more common JFileChooser/File.
  • Pass it back to the host site, which can be done by a sand-boxed applet.

Upvotes: 1

Related Questions