1

First, sorry for my bad english.

I'm not a pro in java and never programmed an applet before. So I'm trying to program a little game for my website. In this game I want a picture as background so i tried to load it with:

Image im = Toolkit.getDefaultToolkit().getImage(path);

That throws a FileNotFoundException, so I tried to creat a new file with FileOutputStream("test.abc"), to look where it will be created. I did this and it was created in my local firefox folder. So how can I load the picture from a folder on the server?

4

2 に答える 2

0

I did this and it was created in my local firefox folder.

Of course it did. Why are you surprised? FileOutputStream doesn't speak HTTP to your server. It talks to a local file system.

So how can I load the picture from a folder on the server?

getCodeBase()+"/back.jpg" should work if back.jpg is in the directory referred to by getCodeBase().

于 2012-07-17T02:20:16.587 に答える
0

Since it is a BG image it might as well be an embedded resource. To 'embed' it, include it in one of the Jars of the applet, then access it according to the link above.

You might also consider deploying a frame (as opposed to an applet) from a link using Java Web Start. That provides lower development/maintenance time and a much better user experience.

于 2012-07-17T23:35:45.877 に答える