How to set automatic focus to Java applet on js - java

I made an applet. It's starting when web page is loaded. But applet lost focus, when web page lost focus too and need to click on area of applet and then it gained focus.
I'm tried variants but it's not helpful
document.getElementById(appletId).focus();
document.getElementById(appletId).requestFocus();
How to set focus to applet in java script?

Ensure the applet element in the HTML declares scriptable=true
Add a public method to the applet that calls requestFocusInWindow().
Call that method using JavaScript.
Be sure to have the JS console open for run time debugging.

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.

java applet freezes browser and way to communicate between javascript and applet

I have applets in my projects. When I want to display applet I load that applet using the applet tag in jsp page and load that page in div tag. it work fine. but when more applets loaded in same browser window then this window is slow down and sometime freezes and applets also becomes unresponsive . when i close the applet the loading div tag still in webpage.
is there any way to communicate betwwen applet and javascript. so that when applet close we are able to remove particular div or set to empty in which applet loaded.
When more applets loaded I check with top command java uses more memory and cpu also.
is there any way to minimise it or communicate between applet and javascript.
Thanks
To communicate with applets, all you need to do is mark methods as as public and call them like so:
<applet code="com.something.MyApplet"
mayscript="true" name="myApplet" width="200" height="100">
Assuming a doSomething method, call it like so from your web page:
myApplet.doSomething("Hello");
As far as the web-page crashing, that's harder to debug, try different embedding methods in different browsers. Try to avoid serving more than one or two applets. Try to figure out if an applet in particular is causing a proble.

Applet and JQuery

Suppose we have an applet on a webpage and JQuery code in the same page, as well. How can we notify JQuery upon an Applet action, for instance a timer in the applet stops and a file system change occurs, and i want to make some process upon this file change in JQuery part as soon as the change occurs. Any suggestions / solutions? Thanks.
You can start with short article: Java - Javascript interaction.
And then see Java-to-Javascript Communication and
JavaScript to Java Communication (Scripting) for more info.

Kill Java Applet via Javascript

I am working for a developing firm and am doing a major redesign on a Web Application, which reloaded everything after each click, to make extensive use of Javascript, so it actually feels like a real Web application. One of the Features is to use a web-based Painter (think of MSPaint on the Web), which I embed on the Page on Demand. After the image is painted and uploaded, the Web-app then unloads the applet and proceeds to show the directory where the file was uploaded to.
This is where Trouble starts. It all works on IE and Safari, but not on Firefox 3.5 (3.0 works perfectly though). Firebug tells me that the expando property is missing.
The Web-app Tiparlo which I was working on before had a similar Problem (in fact, any manipulation done on an applet via jQuery is faulty) but solved that Problem by wrapping a div around and controlling (hide and show) the div instead of the applet. This, unfortunately isn't applicable on this Web-app, because the Applet has to be destroyed and not just hidden and shown, as it takes up too much resources to be run the entire time where it is not needed.
To make it short: Is it possible to make an Applet destroy itself via Javascript? Alternatively: Is there a workaround on the jQuery/expando/applet problem? I know that applet is deprecated in HTML 4.01 strict but changing it to object is not an option right now.
EDIT: I have added a Picture of Firefox + Firebug to show you the actual Error Message. Posting Code does no god, since it works flawless on every other Browser and is a Firefox 3.5 specific Problem. Here be pictures
Note: You can ignore the JS Bug coming from button.js.
You could always load the applet in a an iframe and just navigate away from the page where the applet is loaded. This will kill it.
Your other option if you want to call the destroy from javascript would be to put something like this in.
<script>
document.MyApplet.killApplet();
</script>
public void killApplet() {
AccessController.doPrivileged(new PrivilegedAction() {
public Void run() {
// kill the JVM System.exit(0); return null;
}
});
}
This is not a nice way to kill an applet but on newer browsers it does not throw a JS error, on older ones like IE6 it will throw a js error.
I would suggest that you create a class that monitors the applet to be killed. run the monitor as some sort of servlet and get javascript to post 'kill applet' commands when it needs to be killed.

How to programatically send input to a java app running in a browser window?

Consider the most excellent wordle tag cloud generator:
http://www.wordle.net/create
Entering text into the "textform" textarea and clicking the go button starts up the wordle java applet on that page. No traffic goes back to the server.
How can I cause this to happen programmatically? No hack too cheap!!
background for this question:
"tag cloud" generators?
If you mean starting it programmatically from a browser page, you can use the same type of JavaScript that that page uses, which calls the function Wordle.t() to start the applet.
If you want to call it from a Java program, you can download the Wordle.class or jar file yourself, and call the functions directly.
I'm the creator of Wordle.
In case anyone finds this page in the future, I thought it would be useful to explain that Wordle invokes its applet by constructing an applet tag with a huge <param> containing a sanitized version of whatever text you pasted in. It is the cheapest hack imaginable.

Categories