Create a simple application to open an EXE file on the window with JAVA

Create a simple application to open an EXE file on the window with JAVA
We will learn about how to open EXE file with JAVA. We use netbeans as IDE. So, please create new JAVA Application project. And a small form.

 

Step #1 Create few of label, combobox, and button from tool bar

I use few list item of combobox: Notepad, Window Explorer, Firefox, and Kalkulator as Target EXE

Step #2 Right click on Button to add action performed

Step #3 Use condition to select exe target

String target;
String newTarget = null;
target=(String) jComboBox1.getSelectedItem();
if(target.equals("Notepad"))
{
newTarget = "C:\\Windows\\notepad.exe";
jLabel3.setText(target + " EXECUTED!!");
}
else if(target.equals("Window Explorer"))
{
newTarget = "C:\\Windows\\explorer.exe";
jLabel3.setText(target + " EXECUTED!!");
}
else if(target.equals("Firefox"))
{
newTarget = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
jLabel3.setText(target + " EXECUTED!!");
}
else if(target.equals("Kalkulator"))
{
newTarget = "C:\\Windows\\System32\\calc.exe";
jLabel3.setText(target + " EXECUTED!!");
}
else
{
jLabel3.setText("Silahkan Pilih Salah Satu TARGET EXE");
}
try
{
Process p = Runtime.getRuntime().exec(newTarget);
p.waitFor();
System.out.println(p.exitValue());
}
catch (Exception err)
{
err.printStackTrace();
}

Step #4 Let’s RUN your application [F6]

That’s it!

5 thoughts on “Create a simple application to open an EXE file on the window with JAVA”

  1. Hi! I just love your tutorial! Congratulations!
    I`we just opened a tutorials indexing website and I would like to ask you to submit your tutorials, it will bring you some extra traffic
    Please give a chance for my website: http://www.tutorialswindow.com
    Please let me know about your decision: info@tutorialswindow.com
    Thanks!
    Oh and we also award our users with gift points that can be used to buy ads in our sidebar

Leave a Reply

Your email address will not be published. Required fields are marked *