How to use Java JSmooth to include images in executable file? - java

Im creating a runnable Jar file from Eclipse for a Java file. The Java file has a combobox that changes the image depending on the selection.
Im creating an .exe file for windows using jSmooth.
The .exe runs fine and the images change as expected when the images are in the same file as the .exe file.
How can I "include" the images in the .exe file such that I could send the .exe file to someone without sending them a bunch of images too (using jSmooth).
I do not see a clear method for doing this in JSmooth

What I found out. Using netbeans you can create a label and select an icon in the properties section and this will include the image for you in the jar file.

Related

How can I use resources like pictures and text files when I have BlueJ as my IDE?

I want to use things like text files and png files by using BlueJ. I also want it to work on a computer which does not have the resources.
How to do this?
There are many different ways to use external resources and to ensure they are accessible from another computer.
I'm not familiar with BlueJ but if its like most other IDEs...
For code that you write and run in BlueJ you should be able to put the resources next to the compiled .java files.
Say the resource you placed there was called "img.png" and the class containing your main method was called "Main.class".
To load this file as a BufferedImage you would do the following:
BufferedImage image = ImageIO.read(Main.class.getResourcesAsStream("img.png"));
This will load the file based on its location relative to your main class file.
If you want this file to be accessible to someone running your program on a different computer the best option is to bundle it with you code into a .jar file. See THIS for instructions on how to create a jar.
That will show you how to bundle your code into a jar next you have to add the resources (the "img.png" file). To do this download Jar Splice and follow the on screen instructions, its a very simple program to use.
The output from Jar Splice will be a .jar file containing your code and your resources which can be run on any computer with java installed.

Converting .jar which uses pictures into .exe

I made a program in Java which uses plenty of pictures(every JButton has one).
I exported .jar file from my project and converted it to .exe using JSmooth. When I run .exe, everything works fine on my computer, but on other computers there are no pictures on the buttons. How should I provide those pictures with .exe, so everyone can use program, not only my computer?
I searched everywhere, but I can't find my answer, please help!
This is the example of loading images:
buttons[index].setIcon(new ImageIcon("cards\\"+(index+1)+".png"));
What is the reason that you want the jar file to an exe file?
If you mark the Java file as an executable, then you should be able to execute the jar on windows.
It is possible to package the pictures in your Jar. The preferred way is to adept the script where your IDE creates the jar. Which IDE (integrated development environment) do you use?
--- edited ---
The following code you need in your java code:
buttons[index].setIcon(new ImageIcon(getClass().getClassLoader().getResource((index+1)+".png")));
After creating the Jar file, you can open it with an archive program (like winzip or something like that), and you copy the images in the jar file (root).
If you want to do this program automatically, you need to generate an ant file. And adapt this ant file, so that it copies also the png on the fly, more info can be found here: https://ant.apache.org/manual/index.html

Put an icon on the jar file

I need to put an icon on the jar and I don't know how I can do this. Reading on google some people suggest me to use some wrapper. My question is this: Can I put an image on the jar without install this wrapper? Anyone can help me?
I mean this image:
http://it.tinypic.com/r/ngksp/8
It's not possible (without wrapper). Java is cross-platform language and icon format itself is often "platform dependent" - operating system is in charge of "linking icons to files business".
Set Icon for executable Jar file
How to change executable jar file icon?
How to set ICON image for java.jar executable jar file

exporting runnable jar with eclipse, want to use image files

I am working on a java project and I want to export it to a runnable jar file. This project has a GUI with several background images, and when I run it in eclipse with the images in my project folder it works, but when I try to export it to a jar, I get the following exception when running on cmd: javax.imageio.IIOException: can't read input file!
I have tried moving my images to various places in the project to attempt to include them in the jar, and even then it didn't work. I'm using File objects with commands like
final Image backgroundImage = javax.imageio.ImageIO.read(new File("background.png"));
How do I make it so that I can still use the images (preferably changing as little code as possible)?
Assuming that your image file, background.png, is in the same folder as your class file, replace new File("background.png") with this.getClass().getResource("background.png").

making .exe file for java project containing sqlite

I want to create .exe file for my java project and give it to my friend. I wrote my project in eclipse and it uses sqlite. I don't know how to make a .exe file that can be run in other PCs.
Can any one help?
P.S:I saw this link but it is not useful for me!
Create .jar of an eclipse project that uses Sqlite DB
.exe is a creature of Windows.
To run a Java program, you typically:
Create a .jar file (the "native" Java library format)
Write a DOS/Windows .bat file (or, equivalently, Linux shell script) to run your Java program (using the Java .jar file)
Optionally, create some easy-to-use mechanism for the end user to download the Java JRE (if it's not already installed on their PC).
Your .bat file can be as simple as this:
start javaw -jar myjarfile.jar
Have you considered creating Runnable jar from eclipse.
In eclipse, go to File > Export > Java > Runnable Jar.
There you ll find some options and you can use what suits you. The jar created should be able to run all by itself (obviously it needs the java run time).
Try this out.
I would recommend using a bat file. You can make a double clickable jar file, but I feel that is sometimes restrictive and not intuitive.
Not many end-users know that a jar file is double clickable.
You need to make sure the jar file has a main class and classpath defined. The classpath section in the jar file sometimes causes issues. Like you cannot reference a file or path on the file system. Only files or folders that can be relatively referenced from the location of the jar file.
For windows users, you cannot easily make an exe file from a jar file. There are methods like using jsmooth, that will wrap your jar file into an exe file (bloating the exe file in the process).
The easiest way is to create a bat file. You can easily convert a bat file into an exe and make the exe file have an icon and everything. Link to a converter here:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
First create an executable jar file by clicking on File menu, then export, and then select runnable jar file.
Then select main class and click ok - the jar file will be created.
After that use Launch4j application to create .exe. Launch4j is the best option for creating an exe file.
Then use Inno Setup Creater to create an installer and it is done.

Categories