A "drawn" image suggests you are drawing the image in a paint-type method vis-a-vis showing it in a JLabel. AWT or Swing? I'll assume Swing since it's easier and more fun.
Control the image visibility with a member variable boolean and use either a Swing Timer or a thread for the timing. Change the boolean after the elapsed time and call
repaint.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class ImageErasure extends JPanel implements Runnable {
BufferedImage image;
boolean showImage = true;
public ImageErasure(BufferedImage image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(showImage)
g.drawImage(image, 0, 0, this);
}
public void run() {
int count = 5;
while(count-- > 0) {
try {
Thread.sleep(1000);
} catch(InterruptedException e) {
System.out.println("interrupted");
}
System.out.println("count = " + count);
}
showImage = false;
repaint();
}
private void start() {
Thread thread = new Thread(this);
thread.setPriority(Thread.NORM_PRIORITY);
thread.start();
}
public static void main(String[] args) throws IOException {
String path = "images/Bird.gif";
BufferedImage image = ImageIO.read(new File(path));
ImageErasure test = new ImageErasure(image);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(test);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
test.start();
}
}