Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 05-11-2008, 04:43 AM
Member
 
Join Date: May 2008
Posts: 3
gleb is on a distinguished road
Please Help Me FLASH
Hello, I hope someone can help my get an image in my JPanel flash (on/off) at a predetermined time interval.
For instance, I want it to flash on/off every second. I tried writing the code within a thread like:

class..... extends Thread
.
.
try{
for(int i = 0; i < 10000; i++){
panel.add(image);
Thread.sleep(1000);
panel.remove(image); //panel.add(noImage)
}
}catch InterruptedException e)......

But this only seems to wait the one (1) second until the program runs, and it doesn't actually paint the image. Also, as the image would be removed, I know that all other components would collapse and get funky, so I created another image that is the color of the background, and tried the same thing with it (it's commented) as well as removed it. But the program still idles, and doesn't paint images. I hope someone has a snippet of code or at least share a pointer with me to get me going. I'm a beginner, and any help would be appreciated. Thank you, Gleb
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-11-2008, 08:15 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class Blinking implements Runnable { ImageIcon icon; JLabel label; long delay = 2000; public void run() { int counter = 0; while(true) { try { Thread.sleep(delay); } catch(InterruptedException e) { break; } if(counter++ % 2 == 0) label.setIcon(null); else label.setIcon(icon); label.repaint(); } } private void start() { Thread thread = new Thread(this); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } private JLabel getContent(BufferedImage image) { icon = new ImageIcon(image); label = new JLabel(icon, JLabel.CENTER); label.setBorder(BorderFactory.createEtchedBorder()); label.setPreferredSize(label.getPreferredSize()); return label; } public static void main(String[] args) throws IOException { String path = "images/hawk.jpg"; BufferedImage image = ImageIO.read(new File(path)); Blinking test = new Blinking(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new GridBagLayout()); f.add(test.getContent(image), new GridBagConstraints()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); test.start(); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-11-2008, 07:46 PM
Member
 
Join Date: May 2008
Posts: 3
gleb is on a distinguished road
Thank you hardwired
I will try this code. That you hardwired!!! Your prompt reply is nice.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-11-2008, 07:53 PM
Member
 
Join Date: May 2008
Posts: 3
gleb is on a distinguished road
That is THANK YOU
THANK YOU hardwired, not "That you". There we go. By the way, the method "createEtchedBorder()", I am assuming addresses the issue for when the image is removed, and screen is repainted(cool), it won't distort the way everythink else is packed. Really Cool.
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
JAVA, Ajax, Flash Digital Dispatching JavaServer Pages (JSP) and JSTL 0 02-06-2008 08:49 AM
put a flash file in java programming? notherand New To Java 2 01-23-2008 05:36 AM
Flash toolbar lenny New To Java 1 08-07-2007 07:17 AM
Communication with Expansion Slot Compact Flash device on PDA percivalwcy CLDC and MIDP 0 07-25-2007 10:04 AM
123 Flash Chat 6.6 levent Java Announcements 0 06-05-2007 01:07 PM


All times are GMT +3. The time now is 08:05 AM.


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