Cached Image Applet problem

I've created a SSCE below but I can't seem to find the information I need to
format the code correctly, and I've already wasted a half hour trying to find the link to the info.
I found some mentions of links to the info, but when I followed them they were no longer there.
I would think the FAQ would have something about this but it doesn't appear to....
Can someone please point me to how to get the code formatted correctly?
This problem is only with Java 1.6, it works fine with 1.4, 1.5
In any case my problem is with cached images. It would appear that no matter what I do, I can not
get ImageIO.read() to give me an updated image. I use the same file name and change the file in the
use of my GUI.
To use this code you will have to have an image called gdata.jpg in your "codebase" directory. What
I do is bring up the applet, then change the image file in my "codebase" directory and then click on the button.
You'll see commented code in the actionPerformed which loads a image called gdata1.jpg, if this code is there, the new image
is displayed. The ImageIO.setUseCache(false) appears to do nothing but maybe I'm using it incorrectly.
Help please....
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.JApplet.*;
import javax.swing.event.*;
import java.io.*;
import java.io.Serializable;
import javax.swing.border.*;
public class testApplet extends JApplet implements SwingConstants,
ActionListener
JPanel testPanel = new JPanel();
JButton but = new JButton("test");
URL codeBase,graphURL;
Image gImage = null;
Icon iconImage=null;
// init -- Applet Init
public void init()
Container contentpane = getContentPane();
//Get Server IP information.
codeBase = getCodeBase();
try {
graphURL = new URL(codeBase+"gdata.jpg");
} catch(MalformedURLException e) { }
try {
ImageIO.setUseCache(false);
gImage = ImageIO.read(graphURL);
catch(IOException exc) { }
iconImage = new ImageIcon(gImage);
but.setIcon(iconImage);
testPanel.add(but);
but.addActionListener(this);
contentpane.add(testPanel);
// actionPerformed
public void actionPerformed(ActionEvent e)
if ( e.getSource() == but ) {
//If you uncomment out the 3 lines below, changing the name of the image,
// then it works, otherwise I always get the same image.
// try {
// graphURL = new URL(codeBase+"gdata1.jpg");
// } catch(MalformedURLException ex) { }
try {
ImageIO.setUseCache(false);
gImage = ImageIO.read(graphURL);
catch(IOException exc) { }
iconImage = new ImageIcon(gImage);
but.setIcon(iconImage);
but.revalidate();
testPanel.revalidate();
testPanel.repaint();
return;
Edited by: chippr on Sep 13, 2007 10:32 AM

chippr wrote:
That's odd. It looks like I'm using the same version jre plugin under windows...jre-6u2-windows-i586-p.exe.
Which gives me java 1.6_02
So you changed the image and then hit the button and it worked?Yep.
>
hmmmmm, I wonder what the difference is....I'm using firefox under windows, accessing a linux box
running apache....Same here, except I used appletviewer to test the code on the local machine. Let me upload it to my Linux box (running Apache) and I'll let you know what happens.

Similar Messages

  • Problem: codebase, jar and image reloading problem please help!

    Hi Java Gurus,
    I have written an applet that extends JApplet for viewing webcam. In order to reduce the download time I put my classes into a doorcam.jar file. The following is my <applet> tag in my html file.
    <applet code="CameraApplet.class"
    archive="doorcam.jar"
         codebase = "webcam/classes"
         width="375" height="475">
    <param name="imagePath" value="http://judge/webcam/images">
    <param name="webCamImage" value="door.jpg">
    <param name="COMPort" value="COM2">
    <param name="frameRate" value="10"> <!-- could not exceed more than 10-->
    <param name="host" value="judge">
    </applet>
    The fist problem is that my class file does not get loaded from the jar file if i provide the "codebase" attribute as above. Instead the browser load every single class file from the webserver. This has some problem too. Coz the browser sometimes just thorough NullPointerException or ClassNotFoundException. After much of debugging I found out that the problem is the IE browser which seldom fails to load classes or image file from the server. If i referesh the browser the applet and all its classes loaded successfully and runs smoothly. This behaviour never occurs when running with "appletviewer".
    I wanted all my classes to be loaded from my jar file. After much of trial and error I found out that if i remove "codebase" attribute the browser loads the classes from my jar file and applet loads very fast. This is where the second problem comes in. The browser does not reload my webcam image file so that the webcam become alive with live images, like before.
    If I run on "appletviewer" everything works fine my web cam is displayed properly. But in IE browser the image does not get reloaded when I refresh my image to give live to my webcam display. The refresh method is given below.
    private void refresh(final URL url) {
    Image webCamImage =getImage(url);
    webCamImage.flush(); // flush out the previous image
    webCamImage = getImage(url); // get a new image
    webCamImageIcon.setImage(webCamImage); webCamImageIcon.paintIcon(webCamLabel, webCamLabel.getGraphics(), 15, 15);
    When I add the "codebase" attribute back, the image gets reloaded for every refresh() and everything works fine. But the classes are also loaded from the server. And occasionally also suffers Class loading and image loading problem. As I presented earlier, when I do refreshing in the browser everything gets loaded and the applet function correctly with web cam displaying very well.
    The problem is so strange that I could not find any way to solve it.
    It would be a great help to me if somebody provide me some work around to the problem.
    I tested on Windows 2000, Windows XP, IE 5.5, IE 6 with J2SDK 1.4.0.
    Thank you all very much in advance.
    best regards,
    Judge

    Thank you so much for the suggestions. I did tried the way u suggested. The problem still the same.
    I think its the problem between IE browser and Java Plug-in.
    I which SUN would find these incompatibilities and solve these problems.
    I even tried using java SDK and plug-in 1.4.1 it even worst. It can't even load an applet. And it does not show any loading messages nor any error messages. It just show a cross sign on the upper left coner.
    I would be so glad, if Sun would try to eliminate the inconsistancies such as caching, loading, initializing etc between browser and its Java plug-In. For example, applets behave well in appletviewer and behave unpredictably in browser environment.
    I have seen so many people in the forums with all sorts of problems because of this.
    Right now I m desperately looking for work around to my problem.
    If somebody would provide me with the solution to my problem it would be a great help to me.
    thank you all so much.
    best regards,
    Judge

  • Java + Safari causes page to 'flash' (i.e. reload even cached images)

    Does anyone know if this is able to be corrected or at least why this occurs?
    For Safari 4 beta when Java is active my site http://www.theimagecache.com 'flashes' a lot (i.e.reloads even cached images). Whereas with Java disabled this does not happen and the pages load considerably more quickly.
    I hadn't noticed this before in Safari 3+... but then again... I usually had Java turned off for security reasons so it may have existed then as well.
    But in Firefox 3.1b3, even with Java turned on the pages load very slightly more slowly (i.e. literally only about a fraction of a second more slowly... which is understandable) but they do not 'flash' (i.e. reload cached images).
    Any ideas as to if this can be corrected so viewers that have Java on by default and are using Safari do not see all of this flashing and slower loading?
    Thanks for any input.
    Ron

    Thanks Michael for posting.
    Yes... this Safari beta may be the problem, because even after the images have been cached often many of the images on a new page (that have already been cached) reload.
    Whereas in Firefox 3.1b3 (beta) this does not happen.
    Hopefully they'll get this fixed.
    Thanks again.
    Hope things are going well for you there in Sweden, considering all of the world economic problems.

  • How to solve the image display problem in the iTunes Store

    Hi guys!
    I just want to give a work-around for all of you having the image display problem in the iTunes Store. In my case only the square images in the slider sections won't load:
    I had this in my last W7-installation and got it again in W8 after the first few weeks.
    There are a lot of reports about this problem out there and adhoc solutions like 'clear the cache' or 'reinstall and drink ice tea' that do not work. It is obviously a file request error. It is all about finding out which server addresses get blocked by your computer.
    Solution: Go to your firewall and your Anti-virus-program. There must be a whitelist option. In Kaspersky, check the web-options, the banner-options and the firewall-options, because the all have whitelists. The following addresses have to be whitelisted:
    *.apple
    *.mzstatic.apple.com.akadns.net
    *.mzstatic.com.edgesuite.net
    *.da1.akamai.net
    *.itunes.apple.com
    se.itunes.apple.com
    upp.itunes.apple.com
    ax.init.itunes.apple.com
    xp.apple.com
    *.mzstatic.com
    client-api.itunes.apple.com
    www.apple.com.edgekey.net
    www.isg-apple.com.akadns.net
    Press Ctrl + R in the iTunes Shop then and browse throught the music sections. All images should be displayed correctly now.
    If not, there might be more Apple servers involved in your case. You can find them by running a DNS sniffing tool like the DNS query sniffer by Nirsoft or Wireshark.

    Phone restarting randomly could be loose battery. Tighten by putting a small strip of electrical tape on the back edge.
    THE BITTERNESS OF POOR QUALITY, LINGERS LONG AFTER THE CHEAPNESS OF PRICE, IS SOON FORGOTTEN.

  • Error : 'no cached images'. What does that mean ?

    I try to import some images in Rapidweaver. But in the previewmode I get this errormessage :
    Error exporting image thumbnail for 'name photoalbum' (no cached image) What does that means ?

    Hi
    Error -50 paramErr  Error in user parameter list
    Can there be any external hard disks - if so How is/are it/they formatted ? Must be Mac OS Extended (hfs) if used for Video.
    UNIX/DOS/FAT32/Mac OS Exchange - works for most but not for VIDEO.
    What this means in Your situation is above me.
    • free space on internal boot hard disk? How much ?
    Video codec
    • streamingDV, AIC etc. (not .avi, .mp4, .m4v, .wmv etc as they are containers not codecs)
    Pictures
    • in what format ? .jpg, .bmp, .tif, else ?
    Audio
    • from where/what format ? iTunes, .avi, .mp3, .aiff, else ?
    The "com.apple.iMovie.plist" file
    Many users has not observed that there are TWO libraries.
    • Library - at root level
    • Library - in user/account folder - THIS IS THE ONE to look into
    from Luke Burns
    I fixed the problem.. but it was very, very strange. I had a very long section for credits and set the line spacing to 1.0.. for some reason this caused it. I removed it, and it worked fine. I put it back, and I couldn't preview or play the video.
    I don't know why that could cause that big of a problem, but it did..
    Klaus1
    You need more free space on your hard drive.
    jonorparkerjon
    After phone support from apple I ended up creating a new project and adding all 117 clips back in individually till I found out what clips flagged and would not allow me to export. I had 3 I deleted and replaced and everything works now 1hr after tedious work....
    Where do Your material come from
    • Camera
    • External hard disk
    • USB-memory
    And all are connected so that iMovie can find it ?
    Yours Bengt W

  • Location of cached images from RSS screenblanker

    Where does the screenblanker cache images from an RSS feed?
    I have been using my own Picasa album as source for the screenblanker for more than a year now. A few days ago, images not originating from my album started to show up. At the moment I am not sure if this was a temporary glitch and these images are now taken from the local  cache, or if this is a permanent problem. As new "alien" images are added constantly, I assume the problem is still present.
    When looking at the raw RSS feed, I can't find any hint for images not from my Picasa album, so I don't think this is Google's fault. Has Apple started to "enrich" the feed with other images someone deems interesting?

    The iPhoto library is a SQLite database and must always be treated as a single entity - you can not ever do anything to the individual components of the database
    Moving it is simple - make sure that the EHD is formatted Mac OS extended (journaled) - this is the required format for the iPhoto library) and is connected using a fast hard wired connection like USB, FireWire, Thunderbolt, etc - and then quit iPhoto and drag the library intact as a single entity to the external drive - hold down the option key while launching iPhoto until the select librarywindogw appears and select the new location - fully test it and once you are positive it is complete and at least one successful backup cycle has run so it is backed up in the new location and working you can trash the old library - test one ore time before emptying the trash
    And verify that your backup is backing up the EHD (by default some like TM do not backup the EHD)
    LN

  • I have LR5 on a mac book pro with a external hard drive with LR5 images. my problem is my external hard corrupted reformatedand have to this is expensive and i would to start over in LR5

    i have LR5 on a mac book pro with a WD external hard drive with my with my LR5 images . my problem is my external drive is corrupted .i was told by apple that my macshow the hard drive is there but it is not moumting and have to be reformat. i have to use recovery data to save my images on my external before i can refomat.iam willing to lose my images on my extenal hard drive but i would like to know can i erase my LR5 images and start over or delete LR5 and download it again

    Simply start a new catalog:
    File >> New Catalog
    Choose a new name and save.
    When the empty catalog launches you are ready to start over.

  • My iMac 27" Late 2012 has Image Persistence Problem

    I'm wondering what to do about an annoying image persistence problem on my 27" late 2012 iMac. I got the iMac just a few days ago. Monday actually, so 4 days ago.
    It's the 3.4GHz i7, 8GB, NVIDIA 680MX 1TB fusion drive model.
    Overall it has become the love of my life, but the image persistence thing is getting harder to ignore. This happens after only a few minutes of use. If I follow Apple's instruction on dealing with LCD image persistence, I can make it go away for a while, but it comes back very quickly.
    It is extremely noticeable on a plan dark background. It looks as thought he screen has been left on for a very long time with the same windows open, but it occurrs in less than 5 minutes of use with nothing more intense than a bit of web surfing.
    I've read that this is happening a great deal on these new iMacs, particularly teh 27" machines.
    While the problem seems to be known to those of us afflicted I don't know if Apple has acknowledged an issue or not.
    Here is a sample of the complaints: http://forums.macrumors.com/showthread.php?t=1509571
    I can make the ghost image vanish by bringing up an all white scree for a minute or so or using LCD Scrub.
    I'm wondering if anyone else has foun a solution other than asking for a replacement computer, which Apple seems to be granting on this issue?

    Avoiding image persistence on Apple (IPS) displays
    Avoiding image persistence on Apple LCD displays
    If you cannot resolve the issue yourself, then return the computer for a replacement. You may do this freely within 14 days from date of purchase, so don't delay.

  • How to remove cached images in html whe going from one page to another page

    can anybody help how to remove cached images in html pages.i tried with response.setHeader("no-cache") but it is not working

    thanks,
    can u tell me how to make the browser not to cache images.since iam moving from one page which has images, into another page which having few more images both gets overlaped so how to remove images of previous page.
    thanks in advance

  • Open original image instead of cached image

    While the title in itself is rather self explanatory, I'll elaborate somewhat. The current state of opening sent images means opening the cached version - the file name is wrong in that case, and often times the cached image is in wrong format or size, perhaps even compressed too much; Which might not be the preferable action for a large number of people. Could we possibly get a toggle in Options, or even default left-clicking images to opening the actual image, rather than the image cache?

    Hi Gramps,
    Sorry for this late response. I tried the method you pointed to, but it did not work properly, but I got to doing what I wanted to by changing the .css for the classes and also making a new class in the SpryValidationTextField.css etc.and then applying it in the source code among the span tags.
    I have a new question, but will post it separately.
    zabberwan

  • Caching images

    Hi,
    In my scenario, there can be multiple board area for an user.  When an user logs in 5 images for that board area get picked from the database table and cached.  If any other user for the same board area logs in, system should check cache first.  If found, then it should pick from cache or else go to database table to pick the pictures.  I have pasted the code below to show how the pictures are being cached in my application.  Can anyone help me out with retrieving the pictures explicitly from cache.  A code snippet will be very helpful.  Thanks in advance.
    Regards
    Goutam
    Code to cache image
        IF XSTRLEN( <ls_lso_news_st>-img ) > 0.
          CREATE OBJECT lref_cached_response
            TYPE
              cl_http_response
            EXPORTING
              add_c_msg        = 1.
          lref_cached_response->set_data( <ls_lso_news_st>-img ).
          lref_cached_response->set_status( code = 200 reason = 'OK' ).
          lref_cached_response->server_cache_expire_rel( expires_rel = 180 ).
    GUID / UUID functions
          CALL FUNCTION 'GUID_CREATE'
            IMPORTING
              ev_guid_32 = lf_guid.
          CONCATENATE runtime->application_url '/' lf_guid INTO lf_img_st.
          cl_http_server=>server_cache_upload( url      = lf_img_st
                                               response = lref_cached_response ).
        ENDIF. " XSTRLEN
        ls_s_st_new-header     = <ls_lso_news_st>-header.
        ls_s_st_new-body       = <ls_lso_news_st>-body .
        IF <ls_lso_news_st>-link_name IS NOT INITIAL.
          ls_s_st_new-link_name      = <ls_lso_news_st>-link_name.
          CONCATENATE 'http://' <ls_lso_news_st>-link '/' INTO <ls_lso_news_st>-link.
          ls_s_st_new-link = <ls_lso_news_st>-link.
        ENDIF.

    Hi Raja,
    Thanks for your reply, but i guess i was not able to make you understand my scenario.  Multiple user ID can belong to a board area.  Say, for board area CRM, there are 5 user IDs.  From the admin page, news images are uploaded for a board area and they are saved in database table in XSTRING format.  In my application, I check which board area any user ID belong to and get the images from the database table and set them one by one to cache as I have depicted in the code and display using the URL from the cache, but it happens every time.  what i want now is if any user belonging to same board area logs in, it should not go to the database table to pick the image in XSTRING format and set it to cache one by one again.  For that I saved the news link for that board area in another database table.  So application picks all the links from database table and display them from cache.  But if cache time gets replased, image does not get displayed.  I only want to know the process by which I can find out whether a number of images that I uploaded to cache, those are existing or not, i.e. whether caching time has elapsed.
    Please let me know if you have any suitable solution for this.
    Regards
    Goutam Dutta

  • SSRS indicator image display problem!!

    Hello ALL;
    I am having problem with displaying indicator image in DEV report manager. but same rdl works in QA environment. Both server has SP1 installed. Any Idea? Appreciate for your help. Thanks,

    Hi Techchi,
    Based on the limited information, I cannot figure it out for this issue. As per my understanding, I think this issue can be caused by the browser that run the report manager. If you use IE explorer to render the report, I suggest that you can try to run
    it in compatibility mode. If you are using another browser, I recommend that you should use IE explorer to render the report to check the issue again.
    If this issue still exists, in order to solve the problem more efficiently, I need to clarify some information.
    Are all reports with indicator image cannot render well in DEV report manager? Or just this one report?
    What is the phenomenon about the indicator image display problem? Could you please post a screenshot about this?
    It is benefit for us to do further analysis. Thank you for your understanding.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Having a image alignment problem using clearbox

    Hi,
    I'm having an image alignment problem. I cannot figure it out. I'm using the clearbox - lightbox dreamweaver widget. Using Dreamweaver CS6.
    Actual page located here. Any help would be appreciated.
    http://dirtysouthink.com/gallery/dustin2.html

    This has very little to do with Dreamweaver. DW is merely a tool to assist you in building a web site. It is purely a matter of styling (CSS).
    When I look at the structure, I see
    BODY-CONTENT (width: 490px)
         GALLERY (width: 452px)
              CONTAINER (width: 500px)
                   ITEM (width: 150px)
    From this I can deduce that:
    GALLERY will fit inside BODY-CONTENT
    CONTAINER will NOT fit inside GALLERY or BODY-CONTENT
    ITEM will fit three times into CONTAINER
    To start with, I would reduce the size of the CONTAINER so that it fits inside of its parent. Then I would adjust the width of the ITEM so that only two of them fit inside of the CONTAINER.

  • How does Flex cache images??

    To my understanding, in straight HTML the browser caches image files such that upon return visits (all other things being equal) the browser obtains the image from a browser cache rather than re-downloading.
    Does/can flex make use of the same browser cache?   More specifically, if my flex app downloads a large image file; then the visitor closes his/her browser before reopening it and navigating back to my flex app URL where does the same large image file come from, the imageServer again or from some sort of cache?
    For that matter is the flex app itself cached by the browser such that (assuming no changes were made between visits) a return visit to my flex app url does NOT require the re-download of the app from the server (I know HTML has this capability but not sure about the HTML "wrapper page" which launches the flex app).
    Thanks in advance,

    Sorry for being newbie obtuse but are you saying that FP (Flex Project I assume)'s are an Active X (application) and thus IE does utilize its cache for all HTTP based communications???
    If so then as I understand it, the typical Flex Project has an HTML wrapper which then loads the Flex App (I assume using HTTP).  Subsequent Flex<--->Server communications can be HTTP or other format (AMF which I believe BenForta indicated was HTTP "wrapped" as well but at the moment I am less concerned with this).
    As such is the following correct?
    1.)  IE Browser hits HTML page (url) ----> IE checks its cache; If exists compares vs current version on server; If different download from server else load from cache
    2.)  HTML page calls Flex App (using HTTP???) ----> IE again compares Flex App in cache (if exists) vs. server and if same load else download
    3.)  Flex App retrieves image file names via <mx:RemoteObject> ----- I don't see how browser cache can be used here as results not known until after dbase query completes
    4.)  Flex App uses <mx:RemoteObject> results to retrieve large .jpg files  ---- do these "pass through" the browser (and therefore load and/or store in cache) or are they purely "Flex contained" (and if so does flex have any automatic cache or do I have to perhaps store the jpgs in a shared object if I hope to reuse them without a download)???

  • Image reading problem in servlet

    Image reading problem in servlet
    I am reading an image in servlet and writing it to ServletOutputStream
    The following code works fine unless I change the size of the byte array (for increasing download speed) from 8 to something like 128 or any other higher value
    If I change the value of byte array size the image does not get downloaded properly, I mean the quality of the image changes, it does not looks like the original imageURL url = new URL("http://www.mysite.com/images/img1.jpg");
    URLConnection con = url.openConnection();
    con.setUseCaches(false);
    BufferedInputStream in = new BufferedInputStream(con.getInputStream());
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
    byte b[] = new byte[8];
    while(in.read(b) != -1)
         out.write(b);
         out.flush();               
    out.close();
    in.close();what do I change
    byte array size
    or use the constructor of BufferedInputStream with 2 parameter
    or use the constructor of BufferedOutputStream with 2 parameter
    or use flush outside while loop or what else

    Change your while loop to:
    int count;
    while((count = in.read(b)) != -1)
         out.write(b, 0, count);
         out.flush();               
    }The penultimate time read is called, it may not fill the entire byte array. You only want to write out however much was read into the array.
    For better performance, you should move the flush() outside of the loop too. BufferedOutputStream will flush automatically when its internal buffer is full.

Maybe you are looking for