clear the java buffer

Discussion in 'Java' started by Emmanuel Freund, Nov 24, 2004.

  1. I have a strange error:

    With this function:


    public static ImageIcon loadImageIcon(String file, String iconName) {
    return new ImageIcon(file+ '/' + iconName);
    }
    I first rename Image1.jpg to someImage.jpg and call this function with
    loadImageIcon(myFile,someImage.jpg).
    So Image1.jpg is loaded and paint (with some other functions of course).
    Then during my execution, I rename Image2.jpg to someImage.jpg and call
    loadImageIcon(myFile,someImage.jpg).
    Then the Image loaded is still Image1.jpg.

    Is that possible that Java remember that's the same function called with the
    same variables, and so don't reload the Image and instead take the Image
    from a buffer somewhere?
    And if it's the case, how can we clear the buffer so the Image2.jpg is
    reloaded?
    Thanks,

    --
    Emmanuel
     
    Emmanuel Freund, Nov 24, 2004
    #1
    1. Advertising

  2. Emmanuel Freund

    Ann Guest

    "Emmanuel Freund" <> wrote in message
    news:41a4b600$0$17011$...
    > I have a strange error:
    >
    > With this function:
    >
    >
    > public static ImageIcon loadImageIcon(String file, String iconName) {
    > return new ImageIcon(file+ '/' + iconName);
    > }
    > I first rename Image1.jpg to someImage.jpg and call this function with
    > loadImageIcon(myFile,someImage.jpg).
    > So Image1.jpg is loaded and paint (with some other functions of course).
    > Then during my execution, I rename Image2.jpg to someImage.jpg and call
    > loadImageIcon(myFile,someImage.jpg).
    > Then the Image loaded is still Image1.jpg.
    >
    > Is that possible that Java remember that's the same function called with

    the
    > same variables, and so don't reload the Image and instead take the Image
    > from a buffer somewhere?
    > And if it's the case, how can we clear the buffer so the Image2.jpg is
    > reloaded?
    > Thanks,
    >
    > --
    > Emmanuel
    >

    Try closing the file.
     
    Ann, Nov 24, 2004
    #2
    1. Advertising

  3. > >
    > Try closing the file.
    >
    >


    I may have missed something, but I used an ImageIcon which takes one string
    and no file in its constructor... So I think all the openning-closing
    operations are done in this constructor to which I don't have access.
    So, how I close a file I haven't open ?

    --
    Emmanuel
     
    Emmanuel Freund, Nov 24, 2004
    #3
  4. On Wed, 24 Nov 2004 17:26:39 +0100, Emmanuel Freund wrote:

    > Is that possible that Java remember that's the same function called with the
    > same variables, and so don't reload the Image and instead take the Image
    > from a buffer somewhere?


    It possibly is..
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#getImage(java.net.URL)>

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Nov 24, 2004
    #4
  5. On Wed, 24 Nov 2004 18:04:34 +0100, Emmanuel Freund wrote:

    > ImageIcon which takes one string
    > and no file in its constructor..


    So?
    <http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ImageIcon.html#ImageIcon(java.lang.String)>

    Which, if you look at the source of ..
    <http://www.physci.org/source.jsp?class=javax.swing.ImageIcon>
    You'll notice it calls..
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)>

    'caching'.

    Don't use ImageIcons if you don't want the image cached,
    load the bytes yourself and use ..
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#createImage(byte[])>

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Nov 24, 2004
    #5
  6. Thank you very much Andrew, that was the problem.

    --
    Emmanuel
     
    Emmanuel Freund, Nov 24, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Warren
    Replies:
    3
    Views:
    16,630
    Sam Holden
    Jul 23, 2003
  2. voidstar
    Replies:
    3
    Views:
    10,187
    Mark R Rivet
    Jul 27, 2004
  3. Sam

    CLEAR INPUT BUFFER

    Sam, Oct 28, 2004, in forum: Python
    Replies:
    2
    Views:
    590
  4. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,117
    Mark Fitzpatrick
    Jan 31, 2008
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    1,068
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page