Which means that when I open my program in another computer, I do not need to import image/jar files inorder for the program to work properply ?
3 replies to this topic
#1
Posted 04 August 2011 - 07:36 AM
|
|
|
#2
Posted 05 August 2011 - 06:08 AM
You'll need to package your program in a .jar file along with the images you wish to include. If you're using NetBeans, simply adding the image to a package in your project takes care of this automatically. Alternatively, you can use the JAR command line utility to package your object files and image files, along with any other resources you wish to include.
Docs on the JAR command line utility:
jar-The Java Archive Tool
In your code, you can access the image using the following:
Docs on the JAR command line utility:
jar-The Java Archive Tool
In your code, you can access the image using the following:
Image img = Toolkit.getDefaultToolkit().getImage(MyClass.class.getResource("image.jpg"));
where MyClass is the name of your application class and image.jpg is the filename of your image, obviously. If the image isn't located in the same package as your class, you'll have to provide the absolute path in the filename string.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 05 August 2011 - 07:37 AM
Sorry what I meant was can I don't import the image as in ...
Is there any way that I do not need to import the image and it saved in my jar file.
Which means that when I open the executable jar file, every images are in place so that I do not need to import anything for another comp user.
Hope you get what I'm trying to say.
Is there any way that I do not need to import the image and it saved in my jar file.
Which means that when I open the executable jar file, every images are in place so that I do not need to import anything for another comp user.
Hope you get what I'm trying to say.
#4
Posted 05 August 2011 - 11:06 AM
I don't understand what you're asking. What do you mean by:
Your code will have to load your image files from somewhere in order to be able to run on another computer, so you'll have to transport those images to the other computer somehow.
The way resources (image files are just one kind of resource) are commonly distributed is by wrapping them up with your application's object code in a JAR file (Java ARchive). This is so you don't have to copy all the resource files separately and hope none of them get moved or deleted. Your Java Archive file keeps them all neatly packaged so your application's code knows just where to locate them.
xxxxjayxxx said:
every images are in place so that I do not need to import anything for another comp user.
Your code will have to load your image files from somewhere in order to be able to run on another computer, so you'll have to transport those images to the other computer somehow.
The way resources (image files are just one kind of resource) are commonly distributed is by wrapping them up with your application's object code in a JAR file (Java ARchive). This is so you don't have to copy all the resource files separately and hope none of them get moved or deleted. Your Java Archive file keeps them all neatly packaged so your application's code knows just where to locate them.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









