AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Loading an image file into an applet

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Ed
Guest





PostPosted: Wed Jul 27, 2005 3:37 am    Post subject: Loading an image file into an applet Reply with quote



I'm fairly new to Java, trying to make my first significant Japplet. It's a
small BlackJack game with a swing interface. I'm trying to display GIF
images of the card faces, but I can't get the GIF images to load. I keep
getting security exceptions saying the applet doesn't have read access.

I've got the class files and images packaged in a JAR file. The image files
are stored in a folder named "cardfile". Here's the java code I use to read
the images:

Toolkit kit = Toolkit.getDefaultToolkit();
String blankCard = "cardfile/blank.GIF";
Image blankCardImage = kit.getImage(blankCard);

I launch the applet with this HTML from the same directory as the JAR file:

<applet code="Hello1.class" archive="Hello1.jar" width="800"
height="600"> </applet>

I can run my applet from AppletViewer within my IDE (Netbeans), but I can't
run it from disk or my webserver. Here are the runtime exceptions I keep
getting:

java.security.AccessControlException: access denied
(java.io.FilePermission cardfile/blank.GIF read)
at java.security.AccessControlContext.checkPermission(Unknown
Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at GUItype.<init>(GUItype.java:61)
at Hello1.init(Hello1.java:66)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-Hello1.class"
java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Like I said, I'm new to Java, but best I can tell it says I don't have file
permission to read the GIF files. I thought that Applets could read files
stored within the same codebase that they were launched from, without any
special security settings. When I remove the attempts to read the images,
the applet works fine. Any ideas?


Back to top
Andrew Thompson
Guest





PostPosted: Wed Jul 27, 2005 8:25 am    Post subject: Re: Loading an image file into an applet Reply with quote



On Wed, 27 Jul 2005 03:37:28 GMT, Ed wrote:

Quote:
I'm fairly new to Java, ..

I hope the fact that you're multi-posting means you
are also new to groups and simply don't understand.
<http://www.physci.org/codes/javafaq.jsp#xpost>

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Not Affiliated With Futurama Brass Knuckle Co.

Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Wed Jul 27, 2005 2:42 pm    Post subject: Re: Loading an image file into an applet Reply with quote



"Ed" <nospam (AT) nospam (DOT) com> writes:

Quote:
Toolkit kit = Toolkit.getDefaultToolkit();
String blankCard = "cardfile/blank.GIF";
Image blankCardImage = kit.getImage(blankCard);

This will try to get the image from the local filesystem.

Look into Class.getResource() and the ImageIcon class.

Back to top
Ed
Guest





PostPosted: Thu Jul 28, 2005 4:02 am    Post subject: Re: Loading an image file into an applet Reply with quote


"Tor Iver Wilhelmsen" <jadedgamer (AT) hotmail (DOT) com> wrote

Quote:
"Ed" <nospam (AT) nospam (DOT) com> writes:


Look into Class.getResource() and the ImageIcon class.

Thanks, that did the trick! The Applet tutorial and the Icon tutorial
worked me through it today.



Back to top
Ed
Guest





PostPosted: Thu Jul 28, 2005 4:08 am    Post subject: Re: Loading an image file into an applet Reply with quote


"Andrew Thompson" <SeeMySites (AT) www (DOT) invalid> wrote

Quote:
On Wed, 27 Jul 2005 03:37:28 GMT, Ed wrote:

I'm fairly new to Java, ..

I hope the fact that you're multi-posting means you
are also new to groups and simply don't understand.
http://www.physci.org/codes/javafaq.jsp#xpost

--

No, actually I did it on purpose because I knew I would have a higher
probability of getting a correct answer that way.



Back to top
Andrew Thompson
Guest





PostPosted: Thu Jul 28, 2005 4:48 am    Post subject: Re: Loading an image file into an applet Reply with quote

On Thu, 28 Jul 2005 04:08:09 GMT, Ed wrote:

Quote:
"Andrew Thompson" <SeeMySites (AT) www (DOT) invalid> wrote in message
...
I hope the fact that you're multi-posting means you
are also new to groups and simply don't understand.
...
No, actually I did it on purpose because I knew I would have a higher
probability of getting a correct answer that way.

That won't work for long..
<http://groups.google.com.au/group/comp.lang.java.programmer/msg/10de9f6b8684aa75>

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Now Interactive! Joystick Controls Fry's Left Ear.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.