Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

knowing when images have been loaded. (mediatracker not suitable)

Thread view: 
nntpman68 - 22 Mar 2008 22:49 GMT
Hi,

I'd like to load N (3 < N < 100) images from an applet.

In order to have a non blocking applet UI I'd like to load all images
from a separate thread.

Every time a new image has been completely loaded I would like to be
notified in order to do some processing in in order to redraw.

The Mediatracker is not suitable, as I
can either check fro ALL images to be loaded or I could wait for a
certain image to be loaded.

What I wanted is to be notified for any image (out of a certain list|)
to be completed.

With Mediatracker I would need N threads to achieve this.

What is the recommended way to achieve this?

thanks in advance for any suggestions

n
Knute Johnson - 22 Mar 2008 23:32 GMT
> Hi,
>
[quoted text clipped - 20 lines]
>
> n

The two simplest ways are for you to check to see if the image is loaded
 or wait for it to load.  If that is not workable and you need to be
notified, override ImageObserver.imageUpdate() to call a method or fire
an event when the image is completely loaded.

Why exactly do you need to know that the images have loaded?  There
might be some simpler way to handle your problem.

Signature

Knute Johnson
email s/nospam/linux/

nntpman68 - 24 Mar 2008 21:43 GMT
Hi Knute,

>> Hi,
>>
[quoted text clipped - 28 lines]
> Why exactly do you need to know that the images have loaded?  There
> might be some simpler way to handle your problem.

I think I'd like to start loading multiple images and periodically check
which images are loaded.

what is the method to find out whether an image is completely loaded?

Context:
--------
Well so far I'm just playing.
What I'd like to achieve is to load several 'tiles' and compose them
into an image and overlay them with some additional info.

It should be something like a really, really simple applet version of
Google-maps for fantasy maps.

I'd like to load 'on-screen' tiles.
Whenever a new tile finished I have to recreate a new image.

when no 'on-screem' tiles are outstanding I'd like to start loading
'off-screen' (neighbourhood of on-screen tiles) until new on-screen
tiles are needed.

n
Knute Johnson - 25 Mar 2008 02:51 GMT
> Hi Knute,
>
[quoted text clipped - 53 lines]
>
> n

Well in that case you probably don't really care when they are loaded,
you just want to display them when they are.  You can use the
Applet.getImage() method but that won't download the image until you
draw it.  I would probably use Toolkit.createImage() as I think it will
download the Image synchronously.  You will probably need to put that
code in a separate thread.

If you can use a modern JRE then I would use the ImageIO classes to
download your images.  The advantages are simpler code, more file types
and the end result is a BufferedImage.

Signature

Knute Johnson
email s/nospam/linux/

Mark Space - 23 Mar 2008 01:07 GMT
> In order to have a non blocking applet UI I'd like to load all images
> from a separate thread.

As Knute alluded there are probably better ways of doing this.

First, all images are already loaded asynchronously.  If you use
getImage() it returns immediately, and loads the image in the background.

URL myImageUrl = new URL( "http://myserver/images/myImage.jpg" );
Image myImage = java.awt.Toolkit.getImage( myImageUrl );

The java.awt.Component class implements the ImageObserver interface.
That means all your components (JButtons, Applets, JPanes, JPanels,
etc.) can act as their own image observer. The default behavior is to
call your components repaint() method if the image does not get fully
drawn.  There's a default limit of 100 milliseconds in between calls so
that image loading doesn't completely consume all CPU cycles.

From inside some random component that has a custom image,

public void paint( Graphics g ) {
  g.drawImage( myImage, x, y, this );
  //...
}

will automatically invoke this default behavior.

NOTE 1: Nothing syntax checked.

NOTE 2: From _Learning Java_ by O'Reilly, 3rd ed., pages 709 - 710.  Get
it. Buy it. Love it.
Mark Space - 23 Mar 2008 01:16 GMT
> Image myImage = java.awt.Toolkit.getImage( myImageUrl );

java.awt.Toolkit is abstract.  Need to call

java.awt.Toolkit.getDefaultToolkit()

to get the default one.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.