Appletviewer vs. web browser.

My code is loading up and running in applet viewer, but not in a web browser.

It is far too big a game to post here, but I’m guessing the problem would be in how the images/files are loaded. Is that the first place to look when debugging this problem?

I’m not having a problem loading other applets into the browswer either.

Maybe because I’m using ImageIcon to load the images improperly?

        ImageIcon pausedIcon = new ImageIcon("res/pause.png");
        pausedImage = pausedIcon.getImage();

Only other files I’m loading I do like so:

              String s = new String(applet.getCodeBase().getPath() + animFile);
              System.out.println(s);
              File file = new File(s);

I was correct about the image/file problem.

My solution, in the end, was to use getImage(getCodeBase(), “myfile.png”);
then create ImageIcon with the image to make sure it loaded completely before going on.

It works under Firfox. It does not work under IE. I assume it is a JVM/security problem. I’m running XP. Anyone have any ideas?

If none of the games at http://www.home.zonnet.nl/duijs24/jemu/ don’t work in IE either, I assume java is not enabled in IE.
If you have java installed, you should see at Internet Options->Advanced a checkbox with ‘Java (Sun)’ which has to be enabled. If the checkbox is not there, then maybe java is not properly installed (re-installing java should do the trick).
I assume if the applet works on one browser, it should work in another browser as well, provided that they both support java (and not just the MS VM, which is not really java).
If you want to have your code running on the MS VM as well and you don’t use any features of java 1.2 and up, you should compile your code with a -target 1.1 option.

I hope this helps,
Erik

all the 2d ones work. The 3D ones do not.

Could you go to the Control Panel, open ‘Java Plug-in’ and enable the console? If you try your applet, you will see the output with exceptions etc in the console. You could then copy/paste the console output here.

Erik

file:/C:/PROGRA~2/java/upload2/boxman.jar!/res/red.tda
java.security.AccessControlException: access denied (java.io.FilePermission file
:\C:\PROGRA~2\java\upload2\boxman.jar!\res\red.tda read)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:269)
at java.security.AccessController.checkPermission(AccessController.java:
401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkRead(SecurityManager.java:863)
at java.io.FileInputStream.(FileInputStream.java:100)
at CharacterAnims.(CharacterAnims.java:74)
at GameManager.init(GameManager.java:135)
at sun.applet.AppletPanel.run(AppletPanel.java:353)
at java.lang.Thread.run(Thread.java:534)

Which should be from this bit of code:

URL url = this.getClass().getResource(animFile);
System.out.println(url.getPath());
String s = new String(url.getPath());//applet.getCodeBase().getPath() + animFile);
File file = new File(s);
fileInputStream = new FileInputStream(file);
objectInputStream = new ObjectInputStream(fileInputStream);

Maybe the problem lies in the exclamation point in my path.

You can not read files that is on the local computer from an applet. But you can read files that is provided with the applet using the classloader. You get an InputStream with the following code “getClass().getResourceAsStream(path);”

“path” is relative to the applet, and may look something like “/images/img1.tga”.

The jar is on my pc during development. Hence the C drive.

The function getResourceAsStream() is the thing I was missing. Thank you .