The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 (Not So) Stupid Questions 10: JAR Files
Subject:  The tutorial does have an example
Date:  2006-06-15 16:18:33
From:  wgauvin
Response to: The tutorial does have an example


Oh and here is a example code that I did up to see if it would work. I created a JAR and an image in it.

import javax.swing.ImageIcon;

public class ImageIconLoader {
public static ImageIcon loadImageIcon(String path) throws Exception {
java.net.URL imgURL = ImageIconLoader.class.getResource(path);
if (imgURL != null) {
System.out.println("Loading from: " + imgURL);
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

public static void main(String[] args) throws Exception {
if (args.length > 0) {
loadImageIcon(args[0]);
}
}
}

 Feed java.net RSS Feeds