Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 6:06 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Apr 09, 2012 6:12 pm 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
Hey guys, as the topic implies I am trying to embed my slick applet into a webpage. I poked around the forum and didn't see a topic like this. I found this handy tutorial here:

http://slick.cokeandcode.com/wiki/doku. ... e_web-page

Unfortunately, a few parts are ambiguous, and I didn't see the author's email so I'll defer to the forum.

Some of the main concerns I have are:

Do I need these lwjgl jars in the same directory as the page?

Does this "./mygamelib/" directory need to exist on the webpage? Do the jars go in it?

It seems I need my game as a .jar, is this a runnable jar? Or does it not matter?

Do images get packaged into the jar? I know from previous experience it is a huge pain to find images in a directory once the applet starts running.

Thanks for any help.

Edit: Quick addendum - I've tried the usual way once would embed a java applet with no success, that method being (<APPLET CODE="GameClasses/GameHarness.class" WIDTH=800 HEIGHT=480></APPLET>)


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 11:46 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
i think you should take a look here http://ninjacave.com/slickapplet
however i was playing with it last night and coudn't run it for my project yet


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 3:22 pm 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
Thanks for the tip, that page helped a lot. I'm getting a lot closer to something that works.

I switched to the html provided by that link, but had errors with my code not being signed. To fix that I had to use the pre-signed lwjgl_util_applet provided in the slick download.

Next I got errors due to the logo and progress bar not being loaded. To fix that, I added the lines
Code:
<param name="al_logo" value="appletlogo.png">
  <param name="al_progressbar" value="appletprogress.gif">

Keep in mind we don't need custom images for these, they're packed up in a jar somewhere.

Lastly the natives.jars for the OSes provided by slick have different name than the one in the tutorial (natives-windows.jar as opposed to windows_native.jar) so be sure to change the name in the html. Kinda silly, but that took me a few minutes to notice.

And now my applet it loading, but after a certain amount of progress I get the error:

An error occured while loading theh applet.
Please contact support to resolve the issue.
Fatal error occured (5): Unable to validate certificate chain. Native entry did not have a certificate chain at all.

Of course the interesting part is that last line. I've heard that all the jars in an applet need to have the same signature or it'll throw errors, so maybe this is the cause. I think you also need to pay Oracle or something to be able to sign, but I've heard of people on this forum getting applets to work without needing signatures, so not really sure what's going on there.

Edit: So now I'm in the process of trying to sign my jar file. Will I need to sign any other jars as well? Or just the jar that contains my game? My game doesn't use any special jars other than the default one.


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 6:30 pm 
Offline
Game Developer
User avatar

Joined: Sun Nov 12, 2006 8:40 pm
Posts: 574
Shnagenburg wrote:
I switched to the html provided by that link, but had errors with my code not being signed. To fix that I had to use the pre-signed lwjgl_util_applet provided in the slick download.

Next I got errors due to the logo and progress bar not being loaded. To fix that, I added the lines
Code:
<param name="al_logo" value="appletlogo.png">
  <param name="al_progressbar" value="appletprogress.gif">

Keep in mind we don't need custom images for these, they're packed up in a jar somewhere.

You don't need those lines in recent LWJGL builds, it looks like you are using jars from an old version of LWJGL (especially lwjgl_util_applet.jar). Update to recent version of LWJGL and you won't need those lines (plus it has lots more bug fixes).

Shnagenburg wrote:
Lastly the natives.jars for the OSes provided by slick have different name than the one in the tutorial (natives-windows.jar as opposed to windows_native.jar) so be sure to change the name in the html. Kinda silly, but that took me a few minutes to notice.

And now my applet it loading, but after a certain amount of progress I get the error:

An error occured while loading theh applet.
Please contact support to resolve the issue.
Fatal error occured (5): Unable to validate certificate chain. Native entry did not have a certificate chain at all.

Of course the interesting part is that last line. I've heard that all the jars in an applet need to have the same signature or it'll throw errors, so maybe this is the cause. I think you also need to pay Oracle or something to be able to sign, but I've heard of people on this forum getting applets to work without needing signatures, so not really sure what's going on there.

Edit: So now I'm in the process of trying to sign my jar file. Will I need to sign any other jars as well? Or just the jar that contains my game? My game doesn't use any special jars other than the default one.

That error means the native jars are not signed (the ones included with Slick2D are not). You don't need to sign any jars yourself (unless you need out of applet sandbox access, which you shouldn't need with just Slick2D). Use the pre-signed LWJGL jars provided in the "LWJGL Applet Download Bundle" which you can download from the lwjgl site.


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 8:08 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
if you go to the AppletLoader lwgjl which comes with the download distribution you can take a basic working example from it
that's the basis, so you know it works, then i've tweaked it to use my project files
it doesn't work yet but i already see my splashscreen

also enable in your java settings the java console so you see where it goes wrong!

i've seen that if i create a jar with the embedded dependencies i've got this certification error stuff
but it you just take a build without the dependencies embedded (so with the jars outside your project) it becomes trusted..

good luck !


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 1:53 am 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
Thanks guys, indeed I had downloaded the lwjgl files as opposed to the lwjgl_applet files so that is what caused the issue. Now my game loads and is just a white screen, which is then filled in by any other application on top of it. How exactly do I get to this java console? Can it show whats going on when I run the applet in a browser? Thanks

Edit: Well I finally got it working, turns out you do not include the project name in your main class path. Unfortunately when I create my actual game object, the program dies. So my main question of how to get feedback while running it from off my site remains. Also, should I need anything fancy to load images? Or are they packed into the jar?


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 3:36 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 195
Location: United State of California
I assume you're on Windows? To enable the Java console, go to the control panel, search for java, go to the advanced tab, java console, select show console. You may want to hide the console after your done testing so you don't have to see it every time you use a java program.

_________________
Current Testing Machine:
Windows 7 x64, 4GB RAM DDR3, 3.3ghz AMD Athlon II X3 455, AMD Radeon HD 6800 series.


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 3:54 am 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
Well that is awesome, thanks! As I suspected I'm running into issues loading the files.

Specifically, to load my files I get a list of all the files in my /images/ directory and add them all to my resource pool. Unfortunately, my read permission for the directory is denied, even though I have everything on the server set to be readable. Even if I ask the file object if it .canRead it throws an access denied (java.io.FilePermission images read) exception. Is file i/o (really just reading) something I'll need to sign my jar to do?


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 4:13 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 195
Location: United State of California
It's been awhile so correct me if I'm wrong. With applets, your resources need to be in the same directory as the applet on the server or need to be located within one of the jars signed with your applet. Otherwise, you'll get access denied errors. I suppose this is a security feature so that your applet won't have too much access to the system.

_________________
Current Testing Machine:
Windows 7 x64, 4GB RAM DDR3, 3.3ghz AMD Athlon II X3 455, AMD Radeon HD 6800 series.


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 5:07 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
true, i was quickly testing it one evening and i got to the stage where i saw my splashscreen and the java console loaded the resources
however somewhere he got stuck on the custom cursors or something, but i was already glad that i arrived at that stage..

let me know if you figured this one out, also i access the registry to get the user dir for persisting the scores etc..
so if the user reinstalls the game or get a full version his saved progress is not overwritten however i don't know what it will
do with these applets, if i have rights do read the registry or save in the user folder, (also related to UAC and if you don't have admin rights on your system)


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 12:15 pm 
Offline
Game Developer
User avatar

Joined: Sun Nov 12, 2006 8:40 pm
Posts: 574
For resources (like images, sounds, etc) you need to put them in a jar and load them from there. You do not need to sign the jar with the resources.


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 3:00 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
because for UAC and the user settings my app needs to have access to the registry to read and to find the default user profile folder
ofcourse in an applet i get this:

but how can i create a sort of "un-trusted" certificate?
just to test if it works

or where should i put the user settings to save @ the client without touching the security?

Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "preferences")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.util.prefs.Preferences.userRoot(Unknown Source)
at hh.utils.reg.WinRegistry.<clinit>(WinRegistry.java:23)


Top
 Profile  
 
PostPosted: Thu Apr 12, 2012 7:04 pm 
Offline
Game Developer
User avatar

Joined: Sun Nov 12, 2006 8:40 pm
Posts: 574
With Java applets (and stuff like Flash and HTML5) you don't really have access to save to the file system directly. You can get round this by signing your Java applet and breaking out of the java sandbox, however that is the ugly way to do it.

A nice way to do it is by using HTML5 local storage, all modern browsers support it, and its done by accessing javascript though the Java applet.

Other options include:

1) using php to save data server side
2) using browser cookies (again though javascript).
3) using java muffins.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 2:54 am 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
So to read resources (images, sound) I can put them in a jar, but to write resources I need to use one of those methods above? I've packed up my images in my game.jar, but they still don't seem to want to load. I am using this method:

Code:
System.out.println("trying to get file...");
      Image image = null;
      try {
         image = new Image("/images/backgrounds/bg1.png");
      } catch (SlickException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      System.out.println("got image? " + image.getWidth() );


Where images/backgrounds/bg1.png is included in my jar file. It throws an access denied exception. I really appreciate all the help so far, I feel like we're really close.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 10:22 am 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
adding this to your StatebasedGame can be used to do a switch between
objects that are persisted or cookies with settings to load from

public boolean isApplet(){
return container instanceof AppletGameContainer.Container;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group