How to display an image for a certain amount of time?
How can I change the following code to only display the image for 10 seconds?
publicvoid displayImage(URL url){
JLabel label =new JLabel(new javax.swing.ImageIcon(url));
add( label, BorderLayout.CENTER );// add the image
validate();
}
[490 byte] By [
PeteFa] at [2007-11-27 0:35:54]

# 1
Use a swing Timer to schedule a 10-second delayed task. In the task, you remove the image.
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
Edit: Be sure you don't accidentally use java.util.Timer for this.
Instead, you should make sure you're using javax.swing.Timer for this.
java.util.Timer is not guaranteed to execute the task on the Dispatch Thread.
In fact, in a typical implementation, it is probably NEVER going to execute the task
on the Dispatch Thread.
And you're not supposed to make GUI method calls except on the Dispatch Thread
(the technical name for this thread is AWT Event Thread, even if you're not using AWT)