Applets have security restrictions. Unless you sign them and the
user gives special permissions, they cannot read a file on a user's
computer. However, they can read files from the remote computer --
but not using FileReader. This is because FileReader reads files on
hard drives, and the applet, when running, is no longer *on* the
remote server's computer -- it's on the client's computer.
Instead, generally you can get applet files fetched from the remote
server using getResource and getResourceAsStream (see the class
'java.lang.Class'). This can also be used to grab files when the
program is running as a program and not an applet.
BTW, your code does not run on Mac browsers: likely again it's been
compiled with a bytecode too recent for Java 1.4.2 (OS X's default
Java for web browsers). Please try recompiling it using
javac -target 1.3 ...
[or same in jikes]
On Nov 29, 2005, at 12:59 PM, RDLatimer wrote:
> We're doing a Sugarscape-type project.
> The background sugarscape world is read in with a sugarscape.txt file.
> This works as an application, but doesn't seem to work as an applet.
> Go here:
> I have a screenshot of the intended look - the yellow background
> for the
> If you run the applet model, there is no background?
> Both of the files listed - SugarScape2.java and RuleG2.java
> read the data file - sugarfield.txt (from the sugarfield method)
> FileReader fileReader = new FileReader("sim/app/sugarscape/
> BufferedReader sugarfield = new BufferedReader(fileReader);
> This version works as an application (we see the background)
> java -classpath myMason2.jar:. sim.app.sugarscape.SugarScapeWithUI2
> The applet version doesn't show the background.
> Here's the applet code from the .html file:
> <applet code="sim.display.SimApplet.class" archive="./MyMason2.jar"
> height="30" width="300">
> <param name="CODE" value="sim.display.SimApplet.class">
> <param name="type" value="application/x-java-applet;version=1.1">
> <param name="ARCHIVE" value="./myMason2.jar">
> <param name="Simulation" value="sim.app.sugarscape.SugarScapeWithUI2">
> <param name="Name" value="SugarScape Model">
> Thanks, Randy Latimer