Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: problem: se...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 15 Topic 16050 of 16204
Post > Topic >>

Re: problem: security using IDE's appletviewer

by Knute Johnson <nospam@[EMAIL PROTECTED] > May 5, 2008 at 03:02 PM

bH wrote:
> Hi All,
> 
> Viewing an image, this applet, which compiles and shows an
> image in the browser page IE with no error.
> 
> The image is located >outside< of the program folder.
> 
> I am having the problem with the IDE's appletviewer that
> will not allow a image file to be read. The error
> message on the AppletViewer's message bar at run time is:
> 
> exception:java.security.AccessControlException:Access
>  denied(java.io.FilePermission \C:\JBsm.jpg
> read)
> 
> That said, I have looked at Canadian Mind Products
>  > P words > policy
> 
> The instructions  say to use:
> 
> grant {
> permission java.security.AllPermission;
> };
> 
> I have added these lines above but now there is an error at
>  compile time for this applet:
>  <identifier> expected (obviously after the word "grant")
> 
> Something is missing but I have no idea. I am using
>  jdk1.5.0_12 and jre1.5.0_12
> and stored in that same folder is there jre1.6.0_03 and
>  jre1.6.0_05
> 
> Thanks in advance for your help.
> 
> Here is the applet code:
> 
> im****t java.awt.*;
> im****t java.applet.Applet;
> im****t java.awt.Image;
> 
> public class ImageApplet extends Applet
>   {
>   private Image ioStream;
>   private String errorMessage = null;
> 
>   public void init() {
>     try
>       {
>       //ioStream = getImage(getCodeBase(),
>       // "image/JBsm.JPG" );
>       //above line works with both the IE browser page
>       // and applet viewer
>       ioStream = getImage(getCodeBase(),
> "file:/C:/JBsm.JPG" );
>       //above line works with the Browser page but fails
>       //using the applet viewer
> 
>       //Insure image is downloaded before showing it
>       MediaTracker tracker = new MediaTracker( this );
>       tracker.addImage( ioStream, 0 );
>       tracker.waitForID( 0 );
>       repaint();
>       }
>     catch (InterruptedException netProblem )
>       {
>       errorMessage = "Could not reach image";
>       }
>     }
> 
>   public void paint( Graphics display)
>     {
>     if ( errorMessage == null )
>       display.drawImage( ioStream, 0, 0, this );
>     else
>       display.drawString( errorMessage, 10, 10 );
>     }
>   }
> 
> bH
> 

If you are using the appletviewer or browser to read files from the 
local disk, they must be in the same directory as the applet class 
files.  When downloading from the net, the files to be read must be 
served up by the same server that served the applet class files.

As for the MediaTracker, it is redundant in your code.  If you don't 
need any information from the Image before displaying it, the 
ImageObserver (the 'this' in the drawImage() method) will do everything 
you need to get the image drawn.  Also the repaint() call is not 
required either.

As Mark mentioned, you can embed the image file into a jar and serve 
them up that way.

If you jar up your Applet, access the image file with;

getImage(getClass().getResource("fname.jpg"));

You can specify a directory for the image file but that directory must 
be stored in your .jar file.

-- 

Knute Johnson
email s/nospam/linux/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
      ------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 




 15 Posts in Topic:
problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-05 06:49:23 
Re: problem: security using IDE's appletviewer
Mark Space <markspace@  2008-05-05 09:26:16 
Re: problem: security using IDE's appletviewer
Knute Johnson <nospam@  2008-05-05 15:02:05 
Re: problem: security using IDE's appletviewer
Roedy Green <see_websi  2008-05-06 05:19:44 
Re: problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-06 21:14:28 
Re: problem: security using IDE's appletviewer
Knute Johnson <nospam@  2008-05-06 22:41:20 
Re: problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-06 23:15:05 
Re: problem: security using IDE's appletviewer
Knute Johnson <nospam@  2008-05-07 09:26:35 
Re: problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-07 12:52:20 
Re: problem: security using IDE's appletviewer
Knute Johnson <nospam@  2008-05-07 13:09:04 
Re: problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-07 19:12:12 
Re: problem: security using IDE's appletviewer
Knute Johnson <nospam@  2008-05-07 22:16:30 
Re: problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-07 23:20:54 
Re: problem: security using IDE's appletviewer
Lew <lew@[EMAIL PROTEC  2008-05-08 06:47:22 
Re: problem: security using IDE's appletviewer
bH <bherbst65@[EMAIL P  2008-05-08 04:29:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 7:15:03 CDT 2008.