Images from Jar Files? - How do YOU do it?  
Author Message
Charles Thomas





PostPosted: 2003-7-22 1:35:00 Top

java-programmer, Images from Jar Files? - How do YOU do it?
It occurs to me that this may be the best way to approach this situation:

If you have a stand-alone java application that runs from a JAR file,
and you have images contained in that JAR file that your application
loads... how do YOU do it?

I'm specifically interested in Jar Bundled applications for OSX, but any
code will do.

If anyone could provide sample code, it would be very much appreciated!

CT
 
Harald Hein





PostPosted: 2003-7-22 2:02:00 Top

java-programmer >> Images from Jar Files? - How do YOU do it? "Charles Thomas" wrote:

> It occurs to me that this may be the best way to approach this
> situation:
>
> If you have a stand-alone java application that runs from a JAR
> file, and you have images contained in that JAR file that your
> application loads... how do YOU do it?

new ImageIcon(getClass().getResource("path_to_image_in_the_jar")) /*
.getImage() */;

plus some exception handling.

> I'm specifically interested in Jar Bundled applications for OSX,
> but any code will do.

Platform doesn't matter here.
 
Charles Thomas





PostPosted: 2003-7-22 3:41:00 Top

java-programmer >> Images from Jar Files? - How do YOU do it? In article <email***@***.com>,
Harald Hein <email***@***.com> wrote:

> > If you have a stand-alone java application that runs from a JAR
> > file, and you have images contained in that JAR file that your
> > application loads... how do YOU do it?
>
> new ImageIcon(getClass().getResource("path_to_image_in_the_jar"))


This part is roughly what I'm doing:

url = getClass().getResource("Images/Splash.jpeg");
if (url != null)
{
splash_image = Toolkit.getDefaultToolkit().getImage(url);
}

And "splash_image" is returned as being valid and non-null.

However, when I go to do anything with the image (e.g., display it, or
determine its dimensions), nothing happens. It's like a handle to the
image is getting returned, but not the content of the image itself.

I've tried using MediaTracker to see when it's loaded:

mt = new MediaTracker(image_canvas);
mt.addImage(splash_image, 0);
boolean loaded = mt.waitForAll(10000);

But the image never seems to load.

When call g.drawImage(splash_image, 0,0, null);

subsequently nothing happens, and if I register the canvas as an image
observer, I get an ImageObserver.ABORT followed by an
ImageObserver.ERROR thrown in ImageObserver.imageUpdate().

The odd thing is that the images load just fine with the same exact code
from an OS9 stand-alone java app. But I get these weird problems in OSX.

CT
 
 
James Hicks





PostPosted: 2003-7-22 11:05:00 Top

java-programmer >> Images from Jar Files? - How do YOU do it? If it works on OS9 and not on OSX, it is most likely a JVM issue. Try
another JVM or another platform.

James

"Charles Thomas" <email***@***.com> wrote in
message news:email***@***.com...
> In article <email***@***.com>,
> Harald Hein <email***@***.com> wrote:
>
> > > If you have a stand-alone java application that runs from a JAR
> > > file, and you have images contained in that JAR file that your
> > > application loads... how do YOU do it?
> >
> > new ImageIcon(getClass().getResource("path_to_image_in_the_jar"))
>
>
> This part is roughly what I'm doing:
>
> url = getClass().getResource("Images/Splash.jpeg");
> if (url != null)
> {
> splash_image = Toolkit.getDefaultToolkit().getImage(url);
> }
>
> And "splash_image" is returned as being valid and non-null.
>
> However, when I go to do anything with the image (e.g., display it, or
> determine its dimensions), nothing happens. It's like a handle to the
> image is getting returned, but not the content of the image itself.
>
> I've tried using MediaTracker to see when it's loaded:
>
> mt = new MediaTracker(image_canvas);
> mt.addImage(splash_image, 0);
> boolean loaded = mt.waitForAll(10000);
>
> But the image never seems to load.
>
> When call g.drawImage(splash_image, 0,0, null);
>
> subsequently nothing happens, and if I register the canvas as an image
> observer, I get an ImageObserver.ABORT followed by an
> ImageObserver.ERROR thrown in ImageObserver.imageUpdate().
>
> The odd thing is that the images load just fine with the same exact code
> from an OS9 stand-alone java app. But I get these weird problems in OSX.
>
> CT