Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
reading image files from applet -- newbie question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ed  
View profile  
 More options Jul 27 2005, 1:39 pm
Newsgroups: comp.lang.java.programmer
From: "Ed" <nos...@nospam.com>
Date: Wed, 27 Jul 2005 03:39:04 GMT
Local: Wed, Jul 27 2005 1:39 pm
Subject: reading image files from applet -- newbie question
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?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Head  
View profile  
 More options Jul 27 2005, 4:41 pm
Newsgroups: comp.lang.java.programmer
From: Chris Head <chris2...@hotmail.com>
Date: Wed, 27 Jul 2005 06:41:12 GMT
Local: Wed, Jul 27 2005 4:41 pm
Subject: Re: reading image files from applet -- newbie question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ed wrote:

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

[snip]

Hello,
Try using Applet.getImage() instead of Toolkit.getImage(). There may be
a difference. In fact, you can probably just replace the above three
lines with this:

Image blankCardImage = getImage(getCodeBase(), "cardfile/blank.GIF");

Please note that this is untested.

Good luck,
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFC5yyK6ZGQ8LKA8nwRArA3AJ0e5z0n+G280ZaN9UH4RObazx1RIQCghA01
YrZ2d36IS+MeUr12GyoXMjY=
=Tjj6
-----END PGP SIGNATURE-----


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ed  
View profile  
 More options Jul 28 2005, 2:06 pm
Newsgroups: comp.lang.java.programmer
From: "Ed" <nos...@nospam.com>
Date: Thu, 28 Jul 2005 04:06:03 GMT
Local: Thurs, Jul 28 2005 2:06 pm
Subject: Re: reading image files from applet -- newbie question

Thanks Chris.  I wound up changing my implementation to use ImageIcons,
which I loaded using getResourceAsStream.  That worked like a charm.

"Chris Head" <chris2...@hotmail.com> wrote in message

news:c0GFe.106549$wr.89647@clgrps12...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Thompson  
View profile  
 More options Jul 28 2005, 2:23 pm
Newsgroups: comp.lang.java.programmer
From: Andrew Thompson <SeeMySi...@www.invalid>
Date: Thu, 28 Jul 2005 04:23:25 GMT
Local: Thurs, Jul 28 2005 2:23 pm
Subject: Re: reading image files from applet -- newbie question

On Wed, 27 Jul 2005 03:39:04 GMT, Ed wrote:
> I'm fairly new to Java, ..

Initially I avoided making any comment on this thread,
but since you are a self-professed multi-poster..
<http://groups.google.com.au/group/comp.lang.java.help/msg/7ef76b7149c...>
..you can expect to see a lot more of me, and perhaps
a lot less of 'answers'.

HTH (the other members of the groups)

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Beats A Hard Kick In The Face


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ed  
View profile  
 More options Jul 29 2005, 12:13 am
Newsgroups: comp.lang.java.programmer
From: "Ed" <nos...@nospam.com>
Date: Thu, 28 Jul 2005 14:13:24 GMT
Local: Fri, Jul 29 2005 12:13 am
Subject: Re: reading image files from applet -- newbie question
Oooo, the internet police.

There is a difference between cross-posting and multi-posting.   Judicious
use of the latter should bother nobody, except the odd usenet pedant.

"Andrew Thompson" <SeeMySi...@www.invalid> wrote in message

news:lisdylq9s3j1$.1ikx07l20y7ip.dlg@40tude.net...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google