Current Position:Home > Displaying Image and even hiding after few seconds when button is clicked

Displaying Image and even hiding after few seconds when button is clicked

Update:11-30Source: network consolidation
Advertisement
Hi All,
How to perform an action with a JButton.When clicked image should be displayed and after span of 10 seconds it should get invisible???
Thanks in advance.
regards,
Viswanadh

The Best Answer

Advertisement
kevinaworkman wrote:
For creating an image, look at the getImage() function of the Toolkit class: [http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)|http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)]
Or use the more modern [ImageIO |http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html] class, which is generally preferred over the older Toolkit methods.
As for drawing it, I'd suggest extending a JPanel and overriding its paintComponent functionOr simply use a JLabel that displays only the image. There is no need to subclass JPanel simply for displaying an image, that is re-inventing the wheel.
As for having the image fade away over a few seconds, use a [Swing Timer|http://java.sun.com/javase/6/docs/api/javax/swing/Timer.html] . It ensures that your rendering updates are done on the EDT.
Try some stuff out and post back with an SSCCE if you are still having problems. We will not write the code for you.