Search code examples
javaswinggoogle-earth

Launching Google Earth using Java swing


Can someone please help me how to launch Google Earth application using Java swing? (I mean on click of the GUI button it should open the Google Earth application)


Solution

  • You could try this

       if (Desktop.isDesktopSupported()) {
    try {
        File myFile = new File("/path/to/file.exe");
        Desktop.getDesktop().open(myFile);
    } catch (IOException ex) {
        // no application registered for PDFs
    }
    }
    

    Or by Another Way

      try{
    
        if ((new File("c:\\your_file.exe")).exists()) {
    
            Process p = Runtime
               .getRuntime()
               .exec("rundll32 url.dll,FileProtocolHandler c:\\your_file.exe");
            p.waitFor();
    
        } else {
    
            System.out.println("File does not exist");
    
        }
    
      } catch (Exception ex) {
        ex.printStackTrace();
      }