Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Display an image for a set time

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that should load an image to be set as an icon for a JLabel from JPEG files. The file names are numbers ie. (0.jpg, 1.jpg, ...) so that i can choose the files with a loop and use the loop index as the image name to be retrieved.
Depending on some user action the picture should be set visible for about 5 seconds, set invisible, unload the image, retrieve the next image and then depending on the user action, show it again for another couple of seconds. The way I am doing it it takes the image a long time to be shown. I thought by loading it before I would actually need it that it would speed things up, but thats not what happens. It takes a long time for the image to visible. I have a resource manager class responsible for creating the images from the jpegs. They also have to be resized so that may be why it is taking so long. Here's the resource class makeImage method.


The load and show picture methods are in another class that defines a picture panel



So if the user action is appropriate then the picture panel should be displayed and another one loaded up. I thought using the SwingUtlities would solve any thread issues. Is there some additional thread sequencing that I should do in order for the action to be faster? Thanks for the suggestions.

[ June 23, 2004: Message edited by: Chris Ramsey ]
[ June 23, 2004: Message edited by: Chris Ramsey ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works fast on my computer. If it's still too slow for you I suggest you explore using the createCompatibleImage method in the GraphicsConfiguration class. I've read it can make a difference in rendering time.
 
Chris Ramsey
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Craig! Will try this approach.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic