| | |
Image Array Issue..... Any ideas???
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 43
Reputation:
Solved Threads: 0
I'm trying to create a burst on the screen by running through an image array. As a test I created 3 gif images named One, Two, and Three (each one displays the associated number). The problem is, there is no way to view each image in the array; the only image that is viewable by the human eye is the last one in the array (but each one is viewable if it is selected alone). Does anyone have any advice/links on a solution to this? Been googling this and can't find much help. My code is below.
Java Syntax (Toggle Plain Text)
burst = new BufferedImage[3]; try { burst[0] = ImageIO.read(getClass().getResource("images\\one.gif")); burst[1] = ImageIO.read(getClass().getResource("images\\two.gif")); burst[2] = ImageIO.read(getClass().getResource("images\\three.gif")); //burst[3] = ImageIO.read(getClass().getResource(".gif")); //burst[4] = ImageIO.read(getClass().getResource(".gif")); //burst[5] = ImageIO.read(getClass().getResource(".gif")); //burst[6] = ImageIO.read(getClass().getResource(".gif")); //burst[7] = ImageIO.read(getClass().getResource(".gif")); //burst[8] = ImageIO.read(getClass().getResource(".gif")); //burst[9] = ImageIO.read(getClass().getResource(".gif")); }catch (Exception ex){System.out.println("Invalid Image");} for(int i = 0; i < burst.length; i ++) { for(int t = 0; t < 100; t ++) { g2d.drawImage((BufferedImage)burst[i], 150, 150, null); } }
•
•
Join Date: Jan 2008
Posts: 3,832
Reputation:
Solved Threads: 501
•
•
•
•
Java Syntax (Toggle Plain Text)
for(int i = 0; i < burst.length; i ++) { for(int t = 0; t < 100; t ++) { g2d.drawImage((BufferedImage)burst[i], 150, 150, null); } }
•
•
Join Date: Feb 2008
Posts: 43
Reputation:
Solved Threads: 0
The whole objective to this part of the application is to illustrate an explosion. In theory, the array would have several images, each a different stage or level of the explosion's burst. The reason for the inner loop in my code segment was to attempt a delay so that each image in the array would be viewable instead of only the last. (am doing the explosion this way since the other way wasn't working too well).
•
•
Join Date: Jan 2008
Posts: 3,832
Reputation:
Solved Threads: 501
So you are drawing images intentionally in the same space and intentionally drawing over them, and that is the goal, but is drawing too fast for the human eye to register? How about using the sleep command using threads to pause between images? So if there was a thread t and you wanted to pause for 250 milliseconds, you could do this:
http://java.sun.com/j2se/1.4.2/docs/...tml#sleep(long)
Java Syntax (Toggle Plain Text)
t.sleep (250);
•
•
Join Date: Feb 2008
Posts: 43
Reputation:
Solved Threads: 0
•
•
•
•
So you are drawing images intentionally in the same space and intentionally drawing over them, and that is the goal, but is drawing too fast for the human eye to register? How about using the sleep command using threads to pause between images? So if there was a thread t and you wanted to pause for 250 milliseconds, you could do this:
http://java.sun.com/j2se/1.4.2/docs/...tml#sleep(long)Java Syntax (Toggle Plain Text)
t.sleep (250);
•
•
Join Date: Jan 2008
Posts: 3,832
Reputation:
Solved Threads: 501
I've done it with a JFrame. If it can be done with a JFrame, I imagine it could be done with a JPanel.
You should update the image, repaint, and sleep in a separate thread or a Swing Timer. This animation tutorial might help:http://www.developer.com/java/article.php/893471
The important concept is that the AWT Event Queue needs to be allowed to repaint after you have altered the image.
The important concept is that the AWT Event Queue needs to be allowed to repaint after you have altered the image.
![]() |
Similar Threads
- Ajax javascript test if image file exists (JavaScript / DHTML / AJAX)
- Reformat harddrive, keep image of files? Norton Ghost?? (Storage)
Other Threads in the Java Forum
- Previous Thread: converting JPEG colour image into gray scale image??
- Next Thread: can you help, please
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu windows working






