Reloading an iFrame which was running an Applet - java

I have a web page which is divided into several iFrames.
In each frame is a different solution, like JavaScript in one, flash in another, applet in another.
When a user interacts with the Applet, I am trying to provide a solution where if a certain event happens in the Applet, that the Applet will die and the same iFrame gets loaded with another solution (with an href like solution). I want to be able to load another Applet, or a raw HTML solution, or whatever.
I suspect I need to wrap these solutions in something else like JavaScript, but wondering what would this solution look like.
Thanks in advance.

See Applet.getAppletContext().showDocument(url, target).
Note that it is not guaranteed to be implemented in the JRE/browser combo. the applet is loaded in, let alone work. That is where the JavaScript comes in. ;)

Related

How to wait for a java applet to load when automating Internet Explorer?

I am using mshtml and internet explorer to automate a website. The website is not publicly available. On a page there is a Java Applet which is contained in a APPLET html tag.
The problem is that sometimes the applet takes a long time to load and without it being loaded other controls on the webpage cause errors. I do not need to automate the applet and the applet has nothing to do with what I want to do other than it causes other problems.
Whilst there might be other things you would like to suggest, I would at this stage like to focus on my main question of trying to find some property or event in the HTML which indicates that the Applet is loaded.
Things I have tried to check;
The HTML document has an Applets property which returns the applet collection. This collection contains the applet.
The Applet has a readystate of 4, its object attribute is also not nothing.
Despite these checks the applet is still not loaded.
Anyone coming here, I am sorry but the answer to this question is that I could not find anything in the DOM (the html page) which indicated if the applet had loaded. I, however, believe that it will really depend on the page you are looking at. I think that due to security issues you cannot access the isActive function of the Applet itself. The best you can hope for is that there might be some other html or javascript on the page which also waits for the applet and then you can wait for this.

how to extract HTML data from a webpage which scrolls down for a fixed number of times?

I want to extract HTML data from a website using JAVA. The problem is the webpage keeps scrolling down once the user reaches the bottom of the page. Number of times it scrolls down is fixed. My JAVA code can extract only for the 1st part. How do I extract for the remaining scrolls? Is there a way to load the whole page at once with JAVA? ANy help would be appreciated :)
This might be the type of thing that PhantomJS (http://phantomjs.org/) was designed for. It will crawl entire web pages and even execute JavaScript, using a "real" browser in headless mode. I suggest stopping what you're doing with Java and take a look at PhantomJS instead. It could save you a LOT of time. :)
This type of behavior is implemented in the browser, interpreting the user's scrolling actions to load more content via AJAX and dynamically modifying the in-memory DOM in the browser. Consider that your Java runs in a web container on the server, and that web container (i.e. Tomcat, JBoss, etc) provides a huge amount of underlying code so your app doesn't have to worry about the plumbing.
Conceptually, a similar thing occurs at the client, with the DHTML web page running in its own "container" (the browser), which provides a wealth of functionality, from UI to networking, to DOM, etc. If you remove the browser from the equation and replace it with a Java program, you will need to provide the equivalent of the browser in which the DHTML/Javascript can execute.
I believe that HTMLUnit may fill the bill, but have not worked with it personally.

Displaying a webpage in Java Applet

Can I display a website like wikipedia, google or etc. in my Java applet? I am looking for something like WebBrowser component in C#. Does anyone know how to achieve this?
Take a look at those two answers:
answer 1
answer 2
There are several browser components, and you can see Best Java/Swing browser component? here on SO for some discussion on the "best".
A thought aside - since an applet is already in a web browser, it might be better to bridge to get the browser to display the website you want in, say, an <iframe>, rather than load a browser into a browser.
Swing supports basic HTML (I think version 2.0 or so). So, you can try to use it.
Also there are a several good pure java fully functional HTML browsers.
The question is: why? Java applet runs into browser that knows to show HTML pages. You can easily cause applet to show HTML page into the native browser where it is running now.

Approaches to Creating Screen Capture Functionality on a Web Page

I have read the various posts here on SO regarding screen capturing, but none seem to be answering my situation.
On our website (inside a web page), essentially here is what I would like to be able to do.
User clicks on a 'capture region of screen' button
They get some sort of draggable/sizable box they can use to define the area to capture
the captured area gets converted into a (preferrably) .png
image is uploaded (or at least made available to upload - maybe saved somewhere)
I realize this is not doable with javascript alone. So, I am open to a Java or Flash solution, and/or even a commercial solution (a drop-in java applet that I can add to our site).
So, is something like this available, or any other ideas on how I might approach this?
Thanks.
Check out PhantomJS. http://www.phantomjs.org/
Actually it will re-render page on your server stack and you can save it as a png. Not same as your desired workflow, but definitely worth checking out.

Taking a "screenshot" of a java applet

No. Not pressing PRT Screen. But here is what I want. And I need to know if it can be done and by what means :D
Okay so I have a java applet that runs and displays a walking man.
I need it so when I access a script (in some web scripting language) it takes a "screenshot" of that applet and then saves it on the server. Is this possible? and by what scripting means could I do it?
Thanks in advance!
If there are heavyweight components they might not come out, but the obvious way is:
Create a java.awt.image.BufferedImage
Call createGraphics to create a Graphics instance.
Call update(Graphics) on the applet.
Find a tutorial for converting the BufferedImage to a wire file format.
POST back to the web server.
You can use LiveConnect to connect both ways between Java and JavaScript. It's usually easy to add Java code to an applet simply by adding another reference to the archive attribute of the applet tag.
There are plenty of tutorials on the various parts. I've never done it myself.

Categories