Results 1 to 4 of 4
Thread: Please Help Me FLASH
- 05-11-2008, 03:43 AM #1
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
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
- 05-11-2008, 07:15 AM #2Java 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(); } }
- 05-11-2008, 06:46 PM #3
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
Thank you hardwired
I will try this code. That you hardwired!!! Your prompt reply is nice.
- 05-11-2008, 06:53 PM #4
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
JAVA, Ajax, Flash
By Digital Dispatching in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-06-2008, 07:49 AM -
put a flash file in java programming?
By notherand in forum New To JavaReplies: 2Last Post: 01-23-2008, 04:36 AM -
Flash toolbar
By lenny in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:17 AM -
Communication with Expansion Slot Compact Flash device on PDA
By percivalwcy in forum CLDC and MIDPReplies: 0Last Post: 07-25-2007, 09:04 AM -
123 Flash Chat 6.6
By levent in forum Java SoftwareReplies: 0Last Post: 06-05-2007, 12:07 PM
Bookmarks