This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
actually i want to change the icon of JFrame window
now, jarred that icon image( it is of PNG type) named icons.jar without any subdirectory in it. i tried loading this image after putting this jar file in applets class files directory using this method
but it has not been get loded. where should i put the jar file?
it is definitely highly appreciating, the way you have just given to use. but rather i have still a quary and i hope it will be erased
Rob Prime wrote: You can only use getClass().getResource() if the resource is in the exact same place as the class. Therefore, the image itself should be in the JAR file with the class itself.
you meant to say that, the applet class file must be jarred along with the image file. and the i can access directly this image from within jarred applet class, isn't it?
any way, i have tried without using jar file. just given the image file path as argument to ImageIO.read() method. but i got a strange thing, the image file was taking a long to load (even though is was not loaded)and i couldn't figure out what was occuring in background.
can you figure it out, what was the problem?
[ November 28, 2007: Message edited by: Nidhi Nagre ] [ November 28, 2007: Message edited by: Nidhi Nagre ]
Originally posted by Nidhi Nagre: you meant to say that, the applet class file must be jarred along with the image file. and the i can access directly this image from within jarred applet class, isn't it?
If you don't JAR the applet class file, you don't need to JAR the image file. Just put it in the same folder.
If you JAR the applet class file, include the image file inside that same JAR file, in the same folder as the applet class file.
Joined: Nov 05, 2007
Rob prime wrote: If you don't JAR the applet class file, you don't need to JAR the image file. Just put it in the same folder.
but, even after putting image file in same folder, the method getClass().getResources() was not able to access the image file, instead it flushed java.lang.classnotfoundexception, why??
in your 1st reply, you probabbly meant to say that if image file has not been jarred with applet class file then, instead, without using getClass().getResources method the image file can be acced simply by
but using this i got javax.imageio.IIOutputException
is it due to .PNG ? any other reason?
[ November 29, 2007: Message edited by: Nidhi Nagre ] [ November 29, 2007: Message edited by: Nidhi Nagre ]
To be safe, create a URL based on the location of the HTML page:
This code should be placed inside the applet itself, otherwise you need either a reference to the applet to get access to the getDocumentBase() method, or a reference to the document base itself.
You can use getCodeBase() for the location of the class file if needed.
Joined: Nov 05, 2007
i followed your way, but this time i got something strange,that instead if displaying image, something was running in background seemings for a long time. try to close the applet window was not making any effect too.
after closing it using window task manager,i got the following at java console
i cant figure, what is this mean?
by the way i am using the code
[ November 29, 2007: Message edited by: Nidhi Nagre ]