File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes How I can refresh images in applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "How I can refresh images in applet" Watch "How I can refresh images in applet" New topic
Author

How I can refresh images in applet

fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
Hi,

I have problem with my applet, I have animation with applet, I use timer, every 60 sec refresh the images of animation but don't refresh them, I use the method ImageIO.read(filename), Can you give some idea? or what is my problem?
Thanks a lot
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
Welcome to JavaRanch.

Are you really trying to read from a file? Applets can't access the local file system without being signed. Also, are there any error messages in the Java Console? If so, post them here.

If you post the code that reads and displays the images we might be able to make further suggestions.


Ping & DNS - my free Android networking tools app
fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
thanks, my code en init method is:

The names of images is the same always (loop0.jpg, loop1.jpg...loop10.jpg), only when there is new image a shell program update the images of loop.
In the console o java appear the following message:
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop9.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop8.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop7.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop6.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop5.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop4.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop3.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop2.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop1.jpg read)
access denied (java.io.FilePermission http:\172.29.68.36\centro\Recursos\mexico1\loop0.jpg read)
[ August 25, 2008: Message edited by: Ulf Dittmer ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
You can't use a FileInputStream with an URL. You need to open an URLConnection, and use its InputStream instead.

Please UseCodeTags when you post code of any size. They make the code much easier to read by preserving the indentation.
[ August 25, 2008: Message edited by: Ulf Dittmer ]
fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
Ok, I agree, and then, How I call the images?
Is necesary signed my applet?
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
Put the images in the jar file and use getResource() to return a URL to them.
fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
Is very necessary to use jar file? Can I try signed the applet? or Not is good idea?

thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
There's no need to sign the applet, since the images reside on the same host as the applet.

You don't need to use a jar file - you can put the images into the directory containing the HTML page. But since you'll create a jar file anyway for the classes, you might as well put the images into it, too. It'll speed up their retrieval.
fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
Ok, then, What happen when a try to refresh images during the applet works in the client? Why not the funtion Refrescar() (or Refresh() in english) doesn't work? I checked in other forum, and somebody recoment me to use the method ImgeIO, the method getImage si not good. Excuse me, I new in Java, What I need to do?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
Oh, are you saying that during the runtime of the applet the images on the server can change? And that the second call to ImageIO.read does not load the refreshed image, but rather the original one? Make sure that there's no caching going on anywhere.
fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
Yes, the images in server change every 15 minutes, I need the applet work all day, and It always refresh when update the images. I tryied modified the html file, I disabled the caching, but don't work.May be I don't edit correctly the html file:
<html>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<APPLET CODE=smnAnimaP.class width=900 height=600>
</APPLET>
</HTML>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
Putting an HTTP-EQUIV into the page like that makes sure that the HTML page is not cached; it does nothing for the images.

Make sure that the server actually gets accessed each time the applet wants to reload the images, and also make sure that the server doesn't return a "Not Modified" response (status code 304).
fausto miguel angel sanchez
Greenhorn

Joined: Aug 25, 2008
Posts: 7
I have solved my problem...
Here say me about the cache in the browsers, Is necessary to use class URLConnection, there is method setDefaultUseCaches(false or true), when I open the URL of image, I disabled the cache, some like this:
URLConnection urlconnection;
Image smn_img;
urlConnection=imageURL.openConnection();
urlConnection.setDefaultUseCaches(false);
smn_img=ImageIO.read(imageURL);

Then, the refresh in the applet work fine.
thanks for your comments.
 
 
subject: How I can refresh images in applet