• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How I can refresh images in applet

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
fausto miguel angel sanchez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I agree, and then, How I call the images?
Is necesary signed my applet?
 
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the images in the jar file and use getResource() to return a URL to them.
 
fausto miguel angel sanchez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is very necessary to use jar file? Can I try signed the applet? or Not is good idea?

thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic