Search code examples
javalaunch

How do i launch a program from the desktop through a JPanel


I made a simple JFrame that when you click the screen it opens up JOptionPane where you have to input username and password.

JOptionPane.showConfirmDialog(null, p, "Username and Password", JOptionPane.OK_CANCEL_OPTION);
if (userName.getText().equals(username) && passWord.getText().equals(password)) {
    System.out.println("Correct!!");
} else {
    System.out.println("Incorrect!!");
}

That's the code for the JOptionPane, is there a way to launch a program from the desktop (or another location) through Java?


Solution

  • You can execute a command using Runtime.exec(...):

    http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String)