Putting my Java Slick game onto a website - java

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

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.

get parameter for JApplet not working

I am experiencing a little problem reading parameters from an html page to an applet.
my code (necesssary for question):
on html page:
<PARAM NAME = "name" VALUE = "Nicholus">
in applet (init):
String strName = getParameter("name");
The applet just decides to look at me instead of getting the name value..
a few google search shows im not the only one, except I haddn't yet found the solution, so I decided to post it here in case it was already resolved.
Compare your work with the following working code or post your code if problem still not solved.
Here is the ParamDemo.java code
import java.awt.*;
import java.applet.*;
public class ParamDemo extends Applet{
String strName;
public void start()
{
strName=getParameter("name");
if(strName==null)
strName="Not Found";
}
public void paint(Graphics g)
{
g.drawString("Name :"+strName,10,20);
}
}
Then the Applet.html
<html>
<body>
<applet code="ParamDemo" width="300" height="300">
<param name='name' value="Nicholas">
</applet>
</body>
</html>
Snapshot
[Ps:You need to compile your .java before using in HTML page and make sure that there is no problem related to leter-case of parameter-names as java is case-sensitive.Also the .class and .html files must be in same root folder).
I got it solved, my negligence... my html had many applet codes, the params were not printed within the applet declaration of the one that needs the params. thanks for contributing.

Java applet: custom loading animation going crazy?

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!

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...

Categories