aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "how to update image in Frame" Watch "how to update image in Frame" New topic
Author

how to update image in Frame

sumit karan
Greenhorn

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()
{
super("");
System.out.print("Iframe Constructor....");
showImage();
setLayout(new FlowLayout());
setSize(500, 500);
addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("Bye.");
System.exit(0);
}
}
);
}

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);
mt.waitForID(0);
}
catch (Exception e) { e.printStackTrace(); }
}


public void update( Graphics g) {
paint(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();
iframe.setVisible(true);

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 karan.sumit@gmail.com/sumit_karan@da-iict.org
do try this one!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to update image in Frame
 
Similar Threads
Image not displayed
awt
Want to insert image in frame
Draw bitmap in Canvas
Loading image in Canvas (Urgent)