The moose likes Applets and the fly likes how to update image in Frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "how to update image in Frame" Watch "how to update image in Frame" New topic

how to update image in Frame

sumit karan

Joined: Mar 09, 2005
Posts: 1
I have made a program which takes a image from the current directory and displays it over a frame..But i am calling this frame class from an another class every 5 sec. and in the meantime the image in the current directory changes...But the PROBLEM is that the new image doesn't show up in the new frame which turns up in a new window. Everytime we see the very first image which was there in the first frame.

The code for Frame class is:

import java.awt.*;
import java.awt.event.*;

public class ImageFrame extends Frame {
private static Image _image = null;
MediaTracker mt = null;

public ImageFrame()
System.out.print("Iframe Constructor....");
setLayout(new FlowLayout());
setSize(500, 500);
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {

public void showImage()
try {
mt = new MediaTracker (this);
_image = null;
_image = Toolkit.getDefaultToolkit().getImage("Desk.png");
System.out.print("Iframe showImage....\n");
mt.addImage(_image, 0);
catch (Exception e) { e.printStackTrace(); }

public void update( Graphics g) {

public void paint(Graphics g) {
System.out.println("In Paint....\n");
if(_image != null)
int x = 0, y = 0;
g.drawImage(_image, x, y, this);
else {
g.clearRect(0, 0, getSize().width, getSize().height);


Every 5 sec. i am making a new object of this frame n call its constructor as:

ImageFrame iframe=null;
iframe = new ImageFrame();

I can see the image "Desk.png" changing in the current directory.

the reply for this problem will be appriciated
or you can mail me your solution on
do try this one!
I agree. Here's the link:
subject: how to update image in Frame
It's not a secret anymore!