java- stand alone to applet

Started by
2 comments, last by bschwagg 21 years, 3 months ago
Hi... I''m doing a volunteer project to make a geography game for elementary school kids. I created the game in java using unix. The stand alone application works fine, all the images load and it''s done. I took out the ''main'' function and made my program extend an applet. Everything compiled fine. I then transfered all the files to my windows machine where I''m trying to load up the html file. The applet loads up correctly but I get this error: Exception:java.security.AccessControlException: access denied (java.io.FilePermission map1.jpg read) I''m trying to read this image of off my hard drive. Does this make a difference? Do I need to compile it in windows? The reason I chose java and not c/c++ was because my friend, who is demonstrating this game on a labtop for a conference, uses a Macintosh. She won''t have access to the internet so it has to be a local application. I was hoping an applet would overcome the porting issues. Is java built in to Macs where she could compile it and run it standalone? If so what are the commands- I won''t be seeing her until after she goes to the conference. Thanks alot!
cha cha cha
Advertisement
You can''t access local drives from a java applet, IIRC.
Graphics and other stuff should be downloaded from a webserver.
quote:The reason I chose java and not c/c++ was because my friend, who is demonstrating this game on a labtop for a conference, uses a Macintosh. She won't have access to the internet so it has to be a local application. I was hoping an applet would overcome the porting issues.

I would not build it as an applet unless it has to run in a browser over the internet. I suggest you bundle all your code as an application in a JAR file, as described in a trail in the Java tutorial.

By setting the Main-Class attribute in the JAR file's manifest file you can execute your program just by double-clicking on the JAR file on the desktop of computers that have a JRE properly installed (works at least on Windows and MacOSX computers). The thing to watch out for is how you access your data files from the code inside the JAR file, this might cause problems with paths since you can not make assumptions about what your current directory is when you create relative file names. The getResource method in java.lang.Classloader lets you include your files in the JAR file and access them in a location independent way, I believe that's the "right" way to do it.

MacOSX ships with a nice implementation of JDK1.3 built into the OS, so if your application works with that Java version, then it should run fine on MacOSX (there is also a beta of JDK1.4.1 for MacOSX 10.2 in the apple dev center I hear).

You can access the MacOSX terminal mode (where you can type all standard java tool commands, java, javac etc.) by running the Terminal application in the Applications->Utilities folder. You may want to have your friend type in the java tool commands directly (or create a script file) if you want to ship the application to your friend as loose classes in a folder and have her type in "java package.ClassName" at the prompt. You can even use this approach when you have all your class files in a JAR file (typing in "java -jar JarFile") in order to get a correct 'current directory' (the working directory that you type your commands from) that you can create relative filenames against for your datafiles (only if you don't already use the Classloader.getResource method, and I'm not sure this trick is officially supported).

Recompiling should not be necessary, but if you do it then you need to remember that MacOSX uses a different default character encoding than Windows and Linux so you probably need to use something like 'javac -encoding ISO8859_1 SourceFile.java'.

Phew, long post. Well, good luck, there are a few things to think about when creating multi-platform distributions, but you'll learn them and get them right through testing and experience.

[edited by - HenryAPe on December 26, 2002 5:24:03 PM]
Thank you very much. I had no idea what to do since I''ve never ported any java. I got it running in windows and created a jar file that works. I''ll let you know if all goes well.... : )
cha cha cha

This topic is closed to new replies.

Advertisement