Results 1 to 8 of 8
Thread: Java Applets and Images
- 07-31-2010, 07:06 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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:
Any help would be appreciated :)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
- 07-31-2010, 07:30 PM #2
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.java.security.AccessControlException: access denied (java.io.FilePermission board_all.png read
The error message above implies you are trying to read the image from the local disk.
- 08-01-2010, 10:59 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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
where background is defined in the class.Java Code:Toolkit tk = this.getToolkit(); URL boardUrl = this.getClass().getResource("/board_all.png"); background = = tk.getImage(boardUrl);
When I try
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?:)Java Code:Toolkit tk = this.getToolkit();
- 08-01-2010, 11:23 PM #4
Try removing the / from the path to the image file.
- 08-02-2010, 12:07 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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:
isn't inherited from it's Rectangle superclass.Java Code:this.getToolkit()
Is there a different method in Rectangle, or a generic method, that i could use to get the same result as the first?
- 08-02-2010, 01:35 AM #6
Can you use the ImageIO class's read method to read your image?
- 08-02-2010, 06:46 AM #7
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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
- 08-02-2010, 12:30 PM #8
How are you reading the image file?Caused by: java.security.AccessControlException: access denied (java.io.FilePermission tile_alpha_e.png read)
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
-
Java Applets
By kevinnrobert in forum Java AppletsReplies: 1Last Post: 04-02-2010, 01:16 PM -
Images on JPanels with applets?
By Krooger in forum Java AppletsReplies: 1Last Post: 03-23-2010, 03:41 PM -
images, panels and applets
By jamesfrize in forum Java AppletsReplies: 3Last Post: 03-20-2008, 04:35 PM -
Problems to show images in applets
By Felissa in forum Java AppletsReplies: 1Last Post: 07-06-2007, 09:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks