When i use this from NetBeans it's work but when i use outside of NetBenas don't Code of the ShutDown Class is:
import java.io.IOException; public class ShutDown { public static void shutdown() throws RuntimeException, IOException { String shutdownCommand; String operatingSystem = System.getProperty("os.name"); if (operatingSystem.startsWith("Lin") || operatingSystem.startsWith("Mac")) { shutdownCommand = "shutdown -h now"; } else if (operatingSystem.startsWith("Win")) { shutdownCommand = "shutdown.exe -s -t 0"; } else { throw new RuntimeException("Unsupported operating system."); } Runtime.getRuntime().exec(shutdownCommand); System.exit(0); } }
Code of the ShutDown Button is:
private void ShutDownBtnActionPerformed(java.awt.event.ActionEvent evt) { try { ShutDown.shutdown(); } catch (RuntimeException ex) { Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); } }