Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 06:50 AM
Member
 
Join Date: Jul 2007
Posts: 40
fernando is on a distinguished road
How do erase image drawn
Hi, How do i erase an image drawn in a window in java after a certain amount of time?

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 07:26 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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.
Code:
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(); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting multiple banded image into single banded image... Image enhancement archanajathan Advanced Java 0 01-08-2008 07:29 PM
Image denoising sharonpriya Advanced Java 0 12-17-2007 12:04 PM
how to set an image size valery New To Java 1 08-06-2007 10:27 PM
2D Array to image fred Java 2D 1 07-24-2007 03:52 AM
Image Verification peiceonly Java Servlet 1 04-27-2007 06:50 PM


All times are GMT +3. The time now is 10:36 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org