2

How can I, in an Applet, get the Window containing the Applet as an Window Object?

My goal is to make a screenshot of the content of a "Website".
I tried to make this with the Robot object:

Window window = ???
BufferedImage bufferedImage = new Robot().createScreenCapture(window.getBorder());

To get the border of the browser is the reason why I need this as a window object.

Or is they another possibility to do this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Neifen
  • 2,546
  • 3
  • 19
  • 31
  • 1
    Why do you need it? Come to think of it, why an applet rather than a `JFrame` launched from a link (the you have your 'window'? – Andrew Thompson May 07 '12 at 14:55
  • I have an Applet in my Webapplication to make a Screenshot of it. So i use the Robot Object but for that I need the right Rectangle of the Window... – Neifen May 07 '12 at 15:58
  • but... as far as I understand it the ComponentImageCapture captures only the Java content and not the Html stuff... so I don't know how to use this or a JFrame for this. (Sry I didn't see that it was a question) – Neifen May 07 '12 at 16:23
  • 1
    So you mean you want the **web page** rather than the applet content itself? If so, ignore everything I was saying - you will need to use `Robot` and I was thinking of a different 'frame' (applets are embedded within an **AWT** `Window` for display in the web app.). – Andrew Thompson May 07 '12 at 16:30
  • 1
    yes exactely, appologize my confusing description... – Neifen May 07 '12 at 16:50
  • 1
    Thanks for clarifying that in an edit as well. It is quite clear now. :) – Andrew Thompson May 07 '12 at 16:56

1 Answers1

2

To get the border of the browser is the reason why I need this as a window object.

Figure how to do it in JavaScript. Call the JavaScript from the applet.

This might not be the only way to do it, but it is arguably the best. It uses JS for the type of thing that JS is especially good for, interacting with the web page. Get it working and debugged in JS, then it is a relatively simple matter to call that function from the applet.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • anything that gives access to any information outside the applet window will be security restricted unless the applet is signed. – peterk Apr 16 '13 at 23:22
  • @peterk That is not true. A sand-boxed applet can access other applets in the same page. A sand-boxed applet that declares `MAYSCRIPT` can call JS in the page, anything JS can determine is thereby available to the applet. – Andrew Thompson Apr 17 '13 at 03:18
  • Pardon more accurately no access to anything outside the "page window" - beyond it's inner borders. As I am working on a popup app that was my context :) – peterk Apr 18 '13 at 14:04