Java applet: custom loading animation going crazy? - java

I created a custom loader for my Java applet :
Html Code:
<applet [...]
<PARAM name="image" value="pmap_loader.gif"/>
<PARAM name="boxborder" value="false"/>
<PARAM name="centerimage" value="true"/>
<\applet>
This works fine, but the gif is going crazy. The loading bar fills itself 1000x per second, while as you can see, the gif has been created properly : http://i.imgur.com/MQEof.gif
Does someone have an idea how to fix this? I guess the image is constantly refreshing itself or something like that, but I have no idea how I could fix this.
Thanks for the help!

Related

Why browsers crop java applet?

I created a Java applet supposed to be used in an applet as applets should.
For some reason, all browsers (chrome, firefox, IE) cut it.
I tried using the repaint() and invalidate() methods. I didn't help...
But, interestingly, when I scroll the browser up or down (even a tiny scroll), it immediately fixes. Also, when I use showOptionDialog(Component, String) method, if fixes after the user clicks the OK button on the dialog. It fixes only when the component inputted is the applet itself.
I don't understand why it crops, or how to fix it.
The HTML calling the applet it is very simple. Here is an example of a short piece of HTML code which causes the problem:
<html>
<head>
<title>nispahit</title>
</head>
<body>
<center>
<APPLET CODE="Applet/AppletMain.class" archive="nnis.jar, log4j-1.2.16.jar" WIDTH=800 HEIGHT=600>
<param name="userName" value="http://www.nispahit.com/images/shalom.jpg">
<param name="ColorsContrast" value="241026555"/>
<param name="param2" value="14">
<param name="param3" value="2">
<param name="param3" value="2">
</APPLET>
</center>
</body>
</html>
A solution or workaround will help very much. Any insight would also be helpful.
Thanks.
The cropping happens outside of the applet. There is some block element around the applet (usually a <div>) which is too small to contain the whole applet.
Try to add a div with a red background around the applet so you can see quickly which part is rendered by the browser and which comes from the applet.

Putting my Java Slick game onto a website

I have made a GUI in Java using State Based Game, as it extends StateBasedGame and not JApplet its not a true applet, I want to put it on a website and am unsure on how to do this, I have been told that the following code allows me to make this into an applet using html and not having to edit the Java code:
<applet code="org.lwjgl.util.applet.AppletLoader"
archive="org.lwjgl.util.applet.AppletLoader"
codebase="."
width="640" height="480">
<param name="al_title" value="Ham Blaster">
<param name="al_main" value="org.newdawn.slick.AppletGameContainer">
<param name="game" value="org.javagame.Game">
<param name="al_jars" value="racegame.jar, lwjgl.jar, slick.jar">
<param name="al_windows" value="windows_natives.jar">
<param name="al_linux" value="linux_natives.jar">
<param name="al_mac" value="macosx_natives.jar">
<param name="separate_jvm" value="true">
</applet>
When I run the html code I get the following error on the centre of my screen:
An error occurred while loading the applet. Please contact support to resolve this issue. missing required applet parameter: al_main.
I have looked inside slick for the ApplerGameContainer but I can only find chrome files, I tried putting these in the same directory as the html file but I still get the same error.
If something seems very simple and may seem too obvious to ask me, please tell me because I am new to Java, my previous error with this code was because I did not have my html and lwjgl_util_applet.jar in the same directory, so please tell me anything that may help me.
Emm...
I am not pretty sure, but according to sources the error comes from init method
/*
* #see java.applet.Applet#init()
*/
public void init() {
state = STATE_INIT;
// sanity check
String[] requiredArgs = {"al_main", "al_logo", "al_progressbar", "al_jars"};
for(int i=0; i<requiredArgs.length; i++) {
if(getParameter(requiredArgs[i]) == null) {
fatalErrorOccured("missing required applet parameter: " + requiredArgs[i], null);
return;
}
//... }
}
so it seems your al_main param value is null or something :S
The problem is maybe someplace here
<param name="al_main" value="org.newdawn.slick.AppletGameContainer">
... maybe because I don't see you to init all the rest required params as "al_logo", "al_progressbar"
Anyways, it would be more helpful you to show the problem code
Report if it helps

Why does the start button of applet not display for some people?

I have a simple applet for psychological experiment, I use pxLab libraries ( http://www.pxlab.de/ ).
On this web page ( http://cogsci.fmph.uniba.sk/~stachova/exp/experiment.php ), there should be a start button for the applet and (tried on several computers) there is a button and it works.
However, some of my friends don't see the button when they load the page, and I have teamviewed one of their computers and there really is nothing displayed, where the button should be. Have you any idea, what may be the problem?
Here is how I call the applet:
<APPLET
CODEBASE="."
CODE="ExRunButton.class"
ARCHIVE="exrunbutton.jar, pxlabrt.jar"
ALT="Start design file experiment.pxd"
WIDTH=800
HEIGHT=60
MAYSCRIPT=true>
<PARAM NAME="CommandLine" VALUE="-S2">
<PARAM NAME="DesignFile" VALUE="experimentB.pxd">
<PARAM NAME="DesignFile" VALUE="experimentB.pxd">
<PARAM NAME="StartButtonLabel" VALUE="Začni experiment">
</APPLET>

calling id from applet object throws js error in IE

When calling an applet id from JS giving Object doesn't support this property or method error.
Please check the code...
<!--[if !IE]> Firefox and others will use outer object -->
<object
classid = "java:com.mypack.myclass.ABCClass.class"
type = "application/x-java-applet"
height = "200"
width = "480"
id = "myappletId">
<!-- Konqueror browser needs the following param -->
<param name="cache_archive" value="a.jar, b.jar, c.jar" />
<param name="codebase" value="applets/" />
<param name="OnMouseLeftClickJS" value="showModal()">
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
<object
classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
height = "200"
width = "480"
id = "myappletId">
<param name="code" value="com.mypack.myclass.ABCClass" />
<param name="cache_archive" value="a.jar, b.jar, c.jar" />
<param name="OnMouseLeftClickJS" value="showModal()">
<param name="codebase" value="applets/" />
<strong>No Java Support</strong>
</object>
<!--[if !IE]> close outer object -->
</object>
<!--<![endif]-->
Now, in my showModal() js function I have,
var myId = document.getElementById("myappletId"); //At this point I am getting the object data.
I perform some operations in my modal window which is a jquery modal window and I have a button in it. When I click on that I am calling a function say xyz().
function xyz() {
var myId = document.getElementById("myappletId");
//At this point myId is getting empty.
}
This is happening in only IE Browser. I tested in IE8.
Works good in Firefox and chrome.
I am not navigating my page and on view source I can see my object tag.
Please help me out.
Thanks in advance...
In your comments you have
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
How about using document.getElementById('myappletId').getElementById('innerApplet') ?
It would be great idea to use unique id for inner applet, maybe then your solution would work.
Thanks for your effort guys, the mistake is in my code. When I open a modal window making the object tag visibility hidden in the back. Even I am make it visible after closing the modal window, This IE is not identifying it. Weird but true...

How to add new parameters to a java applet to call another method from javascript?

I am using a java applet to call Web Services. This java applet is embedded in a html web page like this :
<object classid="java:TEST3.class"
codebase="lib/"
type="application/x-java-applet"
width="5000" height="50"
archive="sTest11.jar" name="TEST3" id="TEST3">
<param name="TEST3" value="TEST3" />
alt : TEST3.class
<!-- Safari needs this -->
<param name="JAVA_CODEBASE" value="lib" />
<param name="BGCOLOR" value="000000" />
<param name="TEXTCOLOR" value="FF0000" />
<param name="TEXT" value="Test" />
<param name="SPEED" value="250" />
<param name="RANDOMCOLOR" value="1" />
<param name="mayscript" value="yes"/>
<param name="scriptable" value="true" />
</object>
So when the web page is opened, the applet starts. I have a javascript file which calls the init() method to call a first web service. Then I retrieve datas, that I need to call a second web service. That's why I need here to add parameters to my java applet. If I use in javascript :
document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';
and then
javascript:document.getElementById('TEST3').mymethod2();
it does not work. The applet is not reloaded. (but it works if I put manually a parameter before loading the whole page, so the problem is the reloading of the applet in order to take the new parameter).
I tried to call the stop() method, then the destroy() one, then another init() and then the request I want but it does not work.
I manage to do my requests with different applets (with several innerHTML which create each one applet step by step), but it does not work exactly as I want, and I really would prefer use only one.
If you have any idea, thank you very much for your help.
Try invoking your function like this instead:
document.TEST3.mymethod2();
And see if that works.
EDIT
Based off your comments I understand you were trying to pass additional startup parameters to the Applet on your page. Which is of course not really possible (keyword startup :). With your first method you had this:
document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';
But your object tag (correctly) doesnt have any innerHTML. And params are not specified in the object tag body anyway so no matter what this will have no useful effect. Your second method had this:
javascript:document.getElementById('TEST3').mymethod2();
Which according to your comments works, but of course there is no data getting passed in so your Applet parameters do not change. What you do want to do is this:
javascript:document.getElementById('TEST3').mymethod2(someparameter);
Of course, your method signature on the Applet should match!

Categories