0

I have the following Applet code to load an image.

public void init(){
    str = "Hi, Welcome!";

    sharedImage = getImage(getDocumentBase(), "/Users/Me/ScreenShare/testImage.png");
}
public void paint (Graphics g)
{
    g.drawString(str, 50, 50);
    g.drawImage(sharedImage, 100, 100, this);
}

But, I want to load this dynamically now, because the image from this path will be changing to new image every 5 seconds. How to refresh the image in Applet by itself if I do not use any html page to run the applet?

Please advise.

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
Stella
  • 1,728
  • 5
  • 41
  • 95

1 Answers1

0

Most image loading methods in the JSE will cache images for efficiency. The way around it is ..not to use them, but instead to use lower level methods that will not cause the image to be cached. To do that:

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Could you explain a bit more with the some samples please? – Stella Feb 07 '14 at 05:08
  • Could you try something first ..or pay me consultancy fees? – Andrew Thompson Feb 07 '14 at 06:45
  • Sorry to disturb you :) . I tried already with timer and calling repaint, so that i thought it can update the image periodically on the Applet. But, it is calling the repaint and drawImage function, but Applet not updating the image at run time. Here is the code: timer = new Timer(); timer = new Timer(true); timer.scheduleAtFixedRate(new TimerTask() { public void run() { repaint(); } }, delay, period); – Stella Feb 07 '14 at 07:28
  • For better help sooner, post a [MCTaRE](http://stackoverflow.com/help/mcve) (Minimal Complete Tested and Readable Example) as an [edit to the question](http://stackoverflow.com/posts/21600141/edit). But some advice, it is impractical (for security reasons) to make an applet based MCTaRE that loads images. So sort this out in a normal `JFrame` or `JOptionPane` based GUI with no security manager first. – Andrew Thompson Feb 07 '14 at 07:35