Platform Independent Shutdown Button web component using JavaFX 2.0


Due to this web component you can able to shutdown all type of Operating System .Your can place this component in any of your Web page.By clicking it will shut down your system.In this program you can easily come to know to apply JavaFx CSS Styles to button.


Source code
// Comment
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shutdownsys;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @author allinalljava.blogspot.com */
public class Shutdownsys extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Shut Down");
        Button btn = new Button();
        btn.setText("Shut Down");
               String style_root =" -fx-background-color:   linear-gradient(#ffd65b, #e68400),linear-gradient(#ffef84, #f2ba44), linear-gradient(#ffea6a, #efaa22),linear-gradient(#ffe657 0%, #f8c202 50%, #eea10b 100%), linear-gradient(from 0% 0% to 15% 50%, rgba(255,255,255,0.9), rgba(255,255,255,0));-fx-background-radius: 30;    -fx-background-insets: 0,1,2,3,0;    -fx-text-fill: #654b00;    -fx-font-weight: bold;    -fx-font-size: 14px;    -fx-padding: 10 20 10 20;";
      btn.setStyle(style_root);
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                try {
                    System.out.println("Shut Down");
                    shutdown();
                } catch (RuntimeException ex) {
                    Logger.getLogger(Shutdownsys.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Shutdownsys.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 100, 100));
        primaryStage.show();
    }
    public static void shutdown() throws RuntimeException, IOException {
    String shutdownCommand=null;
    String operatingSystem = System.getProperty("os.name");

  if (operatingSystem.startsWith("Win")) {
  shutdownCommand = "shutdown.exe -s -t 0";
} else if (operatingSystem.startsWith("Linux") || operatingSystem.startsWith("Mac")) {
  shutdownCommand = "shutdown -h now";
} else {
  System.err.println("Shutdown unsupported operating system ...");
    //closeApp();
}


    Runtime.getRuntime().exec(shutdownCommand);
    System.exit(0);
}
}
 

Output Screen
raja P Web Developer

1 comment:

  1. nice blog checkout mine on

    http://www.onjokes.blogspot.com

    feel free to leave a comment

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...