Results 1 to 8 of 8
  1. #1
    Danioson is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default Java Applets and Images

    hello I am an eclipse user. I finished a school project of a game, but now i want to put i up as an applet. I changed a couple things, and it works when i run it in eclipse as an applet.
    I am not sure if this is what i was supposed to do or not, but I uploaded the class files from the bin onto a ftp server in the same directory as the html file and all of the pics. I did not jar it or anything, just copied the classes.
    When i open the webpage the applet doesn't work and I get this message when i ask for details:
    java.lang.reflect.InvocationTargetException
    at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Un known Source)
    at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.io.FilePermission board_all.png read)
    at java.security.AccessControlContext.checkPermission (Unknown Source)
    at java.security.AccessController.checkPermission(Unk nown 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 javax.swing.ImageIcon.<init>(Unknown Source)
    at javax.swing.ImageIcon.<init>(Unknown Source)
    at Frame.<init>(Frame.java:51)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception: java.lang.reflect.InvocationTargetException
    Any help would be appreciated :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    java.security.AccessControlException: access denied (java.io.FilePermission board_all.png read
    How do you try to read the image files? You need to use a method that goes to the server that the applet was loaded from. Look at the getResource() method.

    The error message above implies you are trying to read the image from the local disk.

  3. #3
    Danioson is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default Thanks, but...

    What if I try to create the images in a seperate class that extends Rectangle instead of Applet.
    Right now I'm using this way in my applet class
    Java Code:
    Toolkit tk = this.getToolkit();
    URL boardUrl = this.getClass().getResource("/board_all.png");
    background = = tk.getImage(boardUrl);
    where background is defined in the class.
    When I try
    Java Code:
    Toolkit tk = this.getToolkit();
    in a class that doesn't extend applet the method isn't defined. What is a different method or way of doing it to avoid this issue?:)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Try removing the / from the path to the image file.

  5. #5
    Danioson is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default Hmm.

    The first piece of code works(the method is inherited from its superclass Applet), the problem occurs when i try to use it for a different image file in a different class. The method:
    Java Code:
    this.getToolkit()
    isn't inherited from it's Rectangle superclass.
    Is there a different method in Rectangle, or a generic method, that i could use to get the same result as the first?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Can you use the ImageIO class's read method to read your image?

  7. #7
    Danioson is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default Yeah, but...

    I now get this error
    Java Code:
    java.lang.reflect.InvocationTargetException
    	at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.io.FilePermission tile_alpha_e.png 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 java.io.File.canRead(Unknown Source)
    	at javax.imageio.ImageIO.read(Unknown Source)
    	at Tile.<init>(Tile.java:59)
    	at Bag.reset(Bag.java:38)
    	at Bag.<init>(Bag.java:28)
    	at Frame.<init>(Frame.java:113)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at java.lang.Class.newInstance0(Unknown Source)
    	at java.lang.Class.newInstance(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Exception: java.lang.reflect.InvocationTargetException

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Caused by: java.security.AccessControlException: access denied (java.io.FilePermission tile_alpha_e.png read)
    How are you reading the image file?
    The above error says you are trying to read from the local PC's disk vs reading it from the server that the applet was loaded from.
    Try Building the URL for the image using getCodeBase()

Similar Threads

  1. Java Applets
    By kevinnrobert in forum Java Applets
    Replies: 1
    Last Post: 04-02-2010, 01:16 PM
  2. Images on JPanels with applets?
    By Krooger in forum Java Applets
    Replies: 1
    Last Post: 03-23-2010, 03:41 PM
  3. images, panels and applets
    By jamesfrize in forum Java Applets
    Replies: 3
    Last Post: 03-20-2008, 04:35 PM
  4. Problems to show images in applets
    By Felissa in forum Java Applets
    Replies: 1
    Last Post: 07-06-2007, 09:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •