That's not a very helpful description of a problem you're facing. The approach in general does work; what exactly are you doing that doesn't work? Show us the shortest piece of code that does not do what you expect it to do, and tell us what the differences are.
Thanks very much, I tried the paintIcon idea, and it didn't work, But then i tried Using the ClassLoader idea, with paintIcon as below:
And this works fine! However I tried using .getImage() on the ImageIcon, to get the Image. So that I could then use g.drawImage(...); But that didn't seem to work, kept getting a NullPointerException. As you probably guessed I'm writing a chess program, and the reason I wanted to use g.drawImage(...) was because some of the pieces need to be resized, which can be done with g.drawImage(...), but I'm not sure with paintIcon. Anyway, I just thought, I can just resize them first in photoshop or something, so the paintIcon method should hopefully work fine.
Basically I have a chess application with GUI(based in a JFrame) that I wanted to applet'ise'. But if I just bung the JFrame into the JApplet, then it looks like an extra window has been added on top of applet window. I need the contents of my JFrame to go in the JApplet, so I'm effectively swapping the JFrame for a JApplet.
Thanks for your help, I will probably run into more problems, so I'll let you know. Thanks
Just a wild guess, but I think you may need to use the ImageObserver/MediaTracker mechanism no matter how you load the image, especially once you run the applet over a network. But I guess the ClassLoader approach might somehow sidestep the problem by actually loading the image before returning.
Well, It works fine using just the ImageIcons and paintIcon, except that for the first time I loaded page, not all the images were loaded, not quite sure why. But now it seems to load them all each time. Isn't there a SwingUtilities method, invokeAndWait, or invokeLater, that needs to be used here, I'm not sure?
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss