-
Using ImageIcons in java applets
Hi,
I'm new to this site because I'm having a problem changing one of my java swing applications to an applet so that I can put it on my website. The application is a little poker game I made, and it works great (even as an applet) except for when I run it using a web browser. No matter what I do, it seems that I cannot load the images into my program running it from internet explorer. The images are .jpgs and are in a folder one up from the .class location; I am loading the images using the ImageIcon class, and setting the icons onto buttons. The weird thing is that it all works when I run the applet in my compiler, so I don't know what's wrong. ANY help will be greatly appreciated! Thank you very much!
Babak Rashidi
-
-
youre attempting to read the images directly off disk, rather than usint getDocumentBase(), and hence youre running into a security exception, because applets arent allowed to access the local disk
http://forums.javaboutique.internet....&threadid=2490
-
Thanks for your help!
Wow, you guys had quite the post about it before, thanks a lot! I've made the change, and my problem is better than it used to be (the program now doesn't stop running) except I still have ONE problem, that being that the images still don't show up. Anyway, it looks like it's a problem with where the images are stored or something (Although I know that's not it) but I can figure it out (and if I can't... I'll be back!) And btw cjar, your tutorial on jar files is awesome!!! I recommend anyone trying to put things on the internet to have a look!! I'm actually hoping that may solve my present problem. Thanks!
Babak
-
I had difficulty with using imageicons in an applet, so I nicked the following code from Sun:
protected static ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL = SwingApplet5.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
Then in the method that uses the imageicon, I used:
ImageIcon copyIcon = createImageIcon("images/copy.gif", "Copy");
where the images folder is in the folder containing the applet.
HTH
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks