Image Array Issue..... Any ideas???

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 43
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Image Array Issue..... Any ideas???

 
0
  #1
Feb 24th, 2008
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.

  1. burst = new BufferedImage[3];
  2. try
  3. {
  4. burst[0] = ImageIO.read(getClass().getResource("images\\one.gif"));
  5. burst[1] = ImageIO.read(getClass().getResource("images\\two.gif"));
  6. burst[2] = ImageIO.read(getClass().getResource("images\\three.gif"));
  7. //burst[3] = ImageIO.read(getClass().getResource(".gif"));
  8. //burst[4] = ImageIO.read(getClass().getResource(".gif"));
  9. //burst[5] = ImageIO.read(getClass().getResource(".gif"));
  10. //burst[6] = ImageIO.read(getClass().getResource(".gif"));
  11. //burst[7] = ImageIO.read(getClass().getResource(".gif"));
  12. //burst[8] = ImageIO.read(getClass().getResource(".gif"));
  13. //burst[9] = ImageIO.read(getClass().getResource(".gif"));
  14. }catch (Exception ex){System.out.println("Invalid Image");}
  15.  
  16. for(int i = 0; i < burst.length; i ++)
  17. {
  18. for(int t = 0; t < 100; t ++)
  19. {
  20. g2d.drawImage((BufferedImage)burst[i], 150, 150, null);
  21. }
  22. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: Image Array Issue..... Any ideas???

 
0
  #2
Feb 24th, 2008
One thing to add is that this is all for a JPanel, not an applet. With an applet I'd say a good SLEEP statement would be good, but that's not going to work here.
Last edited by CaffeineCoder; Feb 24th, 2008 at 11:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,832
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Image Array Issue..... Any ideas???

 
0
  #3
Feb 24th, 2008
Originally Posted by CaffeineCoder View Post
  1. for(int i = 0; i < burst.length; i ++)
  2. {
  3. for(int t = 0; t < 100; t ++)
  4. {
  5. g2d.drawImage((BufferedImage)burst[i], 150, 150, null);
  6. }
  7. }
It looks to me like you are drawing all of the images at the same coordinates (150, 150), so wouldn't they all paint over each other and so you'd only see the last one? Also, why are you drawing each of them 100 times?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: Image Array Issue..... Any ideas???

 
0
  #4
Feb 24th, 2008
Originally Posted by VernonDozier View Post
It looks to me like you are drawing all of the images at the same coordinates (150, 150), so wouldn't they all paint over each other and so you'd only see the last one? Also, why are you drawing each of them 100 times?
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).
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,832
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Image Array Issue..... Any ideas???

 
0
  #5
Feb 24th, 2008
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:
  1. t.sleep (250);
http://java.sun.com/j2se/1.4.2/docs/...tml#sleep(long)
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: Image Array Issue..... Any ideas???

 
0
  #6
Feb 24th, 2008
Originally Posted by VernonDozier View Post
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:
  1. t.sleep (250);
http://java.sun.com/j2se/1.4.2/docs/...tml#sleep(long)
Can I do that within a JPanel? If this was an applet that would be my first thought, but with this using JPanel instead of applet, didn't think that was an option.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,832
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Image Array Issue..... Any ideas???

 
1
  #7
Feb 25th, 2008
Originally Posted by CaffeineCoder View Post
Can I do that within a JPanel? If this was an applet that would be my first thought, but with this using JPanel instead of applet, didn't think that was an option.
I've done it with a JFrame. If it can be done with a JFrame, I imagine it could be done with a JPanel.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: Image Array Issue..... Any ideas???

 
0
  #8
Feb 25th, 2008
Originally Posted by VernonDozier View Post
I've done it with a JFrame. If it can be done with a JFrame, I imagine it could be done with a JPanel.
Good to know. I'll try that today and see what I get. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: CaffeineCoder is an unknown quantity at this point 
Solved Threads: 0
CaffeineCoder CaffeineCoder is offline Offline
Light Poster

Re: Image Array Issue..... Any ideas???

 
0
  #9
Feb 26th, 2008
No-go. I'll try doing this in another file in the program but it still just only shows the last image in the array. Been going nuts on this part of the code for the last two months now (trying a few different ways). All I want is to get the app to render some sort of explosion.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,493
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 520
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Image Array Issue..... Any ideas???

 
1
  #10
Feb 26th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC