GUI coding into Desktop Application


Hi everyone! Happy 2022!

Creating GUI applications in Java is good if you enjoy coding and you are familiar with how to run java files by using coding software.  If you are writing that application for someone (it could be your customer)  or if you want other people to use your application without any software need (such as NetBeans IDE),  you need to convert your Java GUI coding into a desktop application.  Today we will learn how to do it!  I want to use the GUI Simple Calculator project that I shared with you previously (link: https://123codingwithme.com/2021/12/11/gui-simple-calculator/).

The following is the step by step workflow;

  • First step to create a *.jar file. Open your NetBeans IDE and select your project. My project name is Calculator.  From the top manu, select Run and click on Clean and Build project. This will let jar file creation to start.  It might take some time so wait until the project completion is finish. My project file extension is located  in my C drive, C:\Java\Calculator.  So,  under the Calculator folder,  there is dist folder.  I will see my jar file there.  So,  my jar file location is  C:\Java\Calculator\dist.  Similarly,  you can find yours.
  • Second, we need a tool to convert java file into a *.exe file.  I will be using a tool called Launch4j. There are many other programs.  You can download it from this link: https://sourceforge.net/projects/launch4j/files/
  • After installation of Launch4j, open it.  You will see the following window.
  • In the basic tab, select your project location (or you can locate a new location) by clicking on the folder icon next to the text field for the Output file and giving a name with an extension of *.exe.  I named it Calculator.exe like the following.
  • Next, click on Jar text field, and again by using the folder icon select your jar file from the dist folder.  You will have the following appearance.
  • You can have an icon for your application.  To have an icon you need to have a file with *.ico format.  I downloaded one from the internet,  however, you can convert a jpg/png file into ico format.  Mine looks like the following.  I saved *.ico file into my project folder.  I named it Calculator.ico.  You need to select that by using the folder icon next to Icon text box.  
  • Next click on the JRE tab from the top menu. JRE stands for Java Runtime Environment which is a software layer that runs additional to a computer’s operating system software and provides the class libraries and other resources that a specific Java program needs to run.
  • In Min JRE version text box, type 1.4.0 (PS: 1.4.0 is just the minimum version of Java required, which basically means the program should launch with any properly installed and configured Java version).
  • Lastly, click on the settings/gear icon from the top menu to build the wrapper. It will open a window and type a file name, like Calculator and click on Save button. 
  • If you see Successfully created write up in the log window, you have your application file in your project folder (or a new folder that you created). You can copy it into your desktop and use it without any software needed.

Enjoy learning and using your application! 

Leave a comment