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.
Related
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.
<html>
<head>
<title>Game</title>
</head>
<body>
<applet code="game/Game" name="Game" archive="Game.jar" width="800" height="600">
No java support.
</applet>
</body>
I'm currently trying to run the above html code in a web browser in order to display my java applet game. The html file is in the same directory as the jar file. What happens when I open the html page is that it asks me if I want to trust the applet (which I just digitally signed myself), and when I say yes, it just displays a blank screen. Also, my CPU usage increases noticeably, so I imagine something is getting stuck.
I can run my applet in Eclipse with no problems. Furthermore, I realize the applet tag is deprecated, however I'm not looking to make this too complicated, plus I need it to run on computers with very outdated browsers.
So, what could the reasons be that my applet will not display? I receive no errors/exceptions, it just shows a white area where my applet should be. Also, when I put the mouse over that area, the cursor does change to what it would be if it were over an applet.
EDIT: Interestingly enough, I was clicking around on the white area where the applet should be, and managed to make one of my in applet menu texts come up. I'm thinking that maybe my images are just not showing up. Why might this be the case?
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.
I have an html page, where I dynamically create applet's HTML code and insert it into the page with with javascript.
After that I call some applet's methods.
Everything works fine in other OS's, and user to work in some Linux machines before.
But now under Linux I get a very strange and too general error message:
Error calling method on NPObject!
I really don't understand what is going on.
When creating applet code not dynamically (not wit JS, just insert it into HTML in the template), it works fine.
What could this be?
Any thoughts?
Thanks.
What could this be?
The latest in a long line of applet/JS/browser/CSS interaction bugs. Here are the hits for applet liveconnect.
Any thoughts?
Don't fight it, but instead use another strategy. I suggest:
Load the applet at page load.
Hide the applet using CSS (move it off the visible page, or make the size small).
Trigger JS that interacts with the CSS To reveal the applet.
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.