How to remove an image after x seconds?

Hi,

I've created an label with an image and what i want is that when i click on a button the image shows up and disappears after x seconds.

I'm not sure if i should use new Thread or Timer/TimerTask for this.

and i'm not sure how to paint something in the image that also dissapears at the same time the image disappears.

any tips? don't need code.

[383 byte] By [deAppela] at [2007-11-27 7:57:00]
# 1

> ...

> any tips? don't need code.

You know the drill here: people who ask for code don't get it...

; )

Try this:

import java.net.URL;

import javax.swing.*;

public class ButtonDemo {

public ButtonDemo(long wait) throws Exception {

JFrame frame = new JFrame("Testing...");

ImageIcon icon = new ImageIcon(new URL("http://www.officenet.no/www/image.do?id=1999"));

frame.add(new VanishImageButton("Duke", icon, wait));

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

frame.pack();

}

public static void main(String[] args) throws Exception {

new ButtonDemo(2000);

}

class VanishImageButton extends JButton implements Runnable {

private long ms;

public VanishImageButton(String title, ImageIcon icon, long ms) {

super(title, icon);

this.ms = ms;

(new Thread(this)).start();

}

public void run() {

try {

Thread.sleep(ms);

} catch(InterruptedException e) {

// ...

} finally {

super.setIcon(null);

}

}

}

}

prometheuzza at 2007-7-12 19:38:48 > top of Java-index,Security,Cryptography...