Hello Every one ...
My proplem started before a month and can't get any answer for it ..
when i create a java program and need to make it an excutable file ..
after done with program that contain's picture's and sound file's I converted it from .java to .jar but the proplem is ,, when I convert the program to .Jar every thing in the Packege deleted .. and can't find a way to extract the package without deleting the picture's and sound file's ...
So my Question is .. How to convert from .java to .Jar without deleting my Picture's and sound file's ?!..

The way i did to convert is by creating a Library then Clean and Build .. i know the proplem is here while doing the Clean and Build thing ..

sry for my bad english ...

I hope to find the Answer ...
thx ,,

they're not deleted, you just need to change your code if you want to use resources within your .jar file.
if I'm not mistaken, you'll need to use the getResource method from the ClassLoader class.

Hello Every one ...
My proplem started before a month and can't get any answer for it ..
when i create a java program and need to make it an excutable file ..
after done with program that contain's picture's and sound file's I converted it from .java to .jar but the proplem is ,, when I convert the program to .Jar every thing in the Packege deleted .. and can't find a way to extract the package without deleting the picture's and sound file's ...
So my Question is .. How to convert from .java to .Jar without deleting my Picture's and sound file's ?!..

The way i did to convert is by creating a Library then Clean and Build .. i know the proplem is here while doing the Clean and Build thing ..

sry for my bad english ...

I hope to find the Answer ...
thx ,,

Here is quite a useful method ive found and use it where ever extraction of Images are needed of course you can change it accordingly:

public Image getImage(String imageFileName) 
{
URL imageURL = getClass().getResource(imageFileName);

if (imageURL == null) 
{
// or otherwise handle the error    
System.out.println("No image named" + imageFileName);
return null;
}
Toolkit tk = Toolkit.getDefaultToolkit();
        
Image img = null;
try 
    {
    img = tk.createImage( (java.awt.image.ImageProducer) imageURL.getContent());
    }
catch (java.io.IOException ex) 
    {
    System.out.println(ex);
    }
return img;

}

how about jar-ifying the whole package?

Icon copy = new ImageIcon( getClass().getResource( "copies.gif" ) );
lblfree = new JLabel (copy);
this is the code am using ,, am currently programming print screen that's why am using this code and can't use the code u gave me or maybe i can but not sure how to add it to my prog ... @cOrRuPtG3n3t
@stultuske am using getresorce() and the when i do the Clean and Build Stuff it clean's my Classes so anything not declare under .Class will be deleted ..
@thepythonguy what do u mean by that how to jar-ifying the whole package !!!
i asked a friend today and he said it's not important to use jar u can do it by using a converter from .Java to .EXE file ... but am still searching for the program ..
thx for your

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.