Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to update image in Frame  RSS feed

sumit karan
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!