• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

how to update image in Frame

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
{
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!
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic