{"comment":{"url":"https://api.github.com/repos/NoraIbrahim/https-github.com-sabreen26-cs381/comments/17477803","html_url":"https://github.com/NoraIbrahim/https-github.com-sabreen26-cs381/commit/57aff8d57ccd166e11e97cd5901792e8cd368994#commitcomment-17477803","id":17477803,"user":{"login":"NoraIbrahim","id":17978194,"avatar_url":"https://avatars.githubusercontent.com/u/17978194?v=3","gravatar_id":"","url":"https://api.github.com/users/NoraIbrahim","html_url":"https://github.com/NoraIbrahim","followers_url":"https://api.github.com/users/NoraIbrahim/followers","following_url":"https://api.github.com/users/NoraIbrahim/following{/other_user}","gists_url":"https://api.github.com/users/NoraIbrahim/gists{/gist_id}","starred_url":"https://api.github.com/users/NoraIbrahim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoraIbrahim/subscriptions","organizations_url":"https://api.github.com/users/NoraIbrahim/orgs","repos_url":"https://api.github.com/users/NoraIbrahim/repos","events_url":"https://api.github.com/users/NoraIbrahim/events{/privacy}","received_events_url":"https://api.github.com/users/NoraIbrahim/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"57aff8d57ccd166e11e97cd5901792e8cd368994","created_at":"2016-05-14T18:45:30Z","updated_at":"2016-05-14T18:45:30Z","body":"package cal;\r\n\r\n\r\n\r\nimport javafx.application.Application;\r\n\timport javafx.event.ActionEvent;\r\n\timport javafx.event.EventHandler;\r\n\timport javafx.scene.Scene;\r\n\timport javafx.scene.control.Button;\r\n\timport javafx.scene.layout.GridPane;\r\n\timport javafx.stage.Stage;\r\n\timport javafx.beans.property.SimpleStringProperty;\r\n\timport javafx.beans.property.StringProperty;\r\n\timport javafx.geometry.Insets;\r\n\timport javafx.geometry.Pos;\r\n\timport javafx.scene.control.TextField;\r\n\timport javafx.scene.layout.BorderPane;\r\n\timport javafx.scene.layout.Priority;\r\n    import javax.script.ScriptEngine;\r\n\timport javax.script.ScriptEngineManager;\r\n\t public class cal extends Application {\t\t\t\r\n\t\t ScriptEngineManager manager=new ScriptEngineManager();\r\n\t\t ScriptEngine engine=manager.getEngineByName(\"JavaScript\");\r\n\t\t boolean frac=false;\r\n\t\t private final StringProperty v= new SimpleStringProperty(\"\");\r\n\t\t class NumberButtonHandler implements EventHandler<ActionEvent>  {\r\n\t\t    \t\r\n\t\t        private final String number ;\r\n\t\t        \r\n\t\t        NumberButtonHandler(String number) {\r\n\t\t            this.number = number ;\r\n\t\t           \r\n\t\t        }\r\n\t\t        @Override\r\n\t\t        public void handle(ActionEvent event) {\r\n\t\t    \r\n\t\tString newn=v.get();\r\n\t\t        v.set( newn+number);\r\n\t\t        }\r\n\t\t}\r\n\t\t  \r\n\t\t    @Override\r\n\t\t    public void start(Stage primaryStage) {\r\n\r\n\t\t        GridPane grid = createGrid();\r\n\t\t        grid.setStyle(\"-fx-background-color:cyan\");\r\n\t\t        Button add;\r\n\t\t        TextField displayField;\r\n\t\t        Button  seven =  createNumberButton(\"7\");\r\n\t\t        grid .add(seven, 0, 0);\r\n\t\t\t\tButton four =  createNumberButton(\"4\");\r\n\t\t\t\r\n\t\t\t\tgrid .add(four, 0, 1);\r\n\t\t\t\tButton one =  createNumberButton(\"1\");\r\n\t\t\t\r\n\t\t\t\tgrid .add(one,0,2);\r\n\t\t\t\tButton eight =  createNumberButton(\"8\");\r\n\t\t\t\r\n\t\t\t\tgrid .add(eight, 1, 0);\r\n\t\t\t\tButton five = createNumberButton(\"5\");\r\n\t\t\t\t \r\n\t\t\t\tgrid .add(five, 1, 1);\r\n\t\t\t\tButton two =  createNumberButton(\"2\");\r\n\t\t\t\t\r\n\t\t\t\tgrid .add(two, 1, 2);\r\n\t\t\t\r\n\t\t\t\tButton nine=  createNumberButton(\"9\");\r\n\t\t\t\tgrid .add(nine, 2, 0);\r\n\t\t\t\tButton six = createNumberButton(\"6\");\r\n\t\t\t\tgrid .add(six, 2, 1);\r\n\t\t\t\tButton three =  createNumberButton(\"3\");\r\n\t\t\t\tgrid .add(three, 2, 2);\r\n\t\t        Button zeroButton = createNumberButton(\"0\");\r\n\t\t         grid.add(zeroButton, 0,3);\r\n\t\t         Button modulars = createButton(\"%\");\r\n\t\t         modulars.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t grid.add(modulars, 2, 3);\r\n\t\t\t\t Button division = createButton(\"/\");\r\n\t\t\t\t division. setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t grid.add(division, 3, 0);\r\n\t\t\t\t Button mulitp =createButton(\"*\");\r\n\t\t\t\t mulitp.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t grid.add( mulitp, 3, 1);\r\n\t\t\t\t Button\t sub = createButton(\"-\");\r\n\t\t\t\t grid.add(sub, 3, 2);\r\n\t\t\t\t sub.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t add =createButton(\"+\");\r\n\t\t\t\t grid.add(add, 3, 3);\r\n\t\t\t \t add.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button\tarrow = createButton(\"←\");\r\n\t\t\t\t grid.add(arrow, 4, 0);\r\n\t\t\t\t arrow.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button\tarc1 = createButton(\"(\");\r\n\t\t\t\t grid.add(arc1, 4, 1);\r\n\t\t\t\t arc1.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button x = createButton(\"^2\");\r\n\t\t\t\t grid.add(x, 4, 2);\r\n\t\t\t\t x.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button equal=createButton(\"=\");\r\n\t\t\t\t grid.add(equal,4,3,2,1);\t\r\n\t\t\t\t equal.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button arc2 = createButton(\")\");\r\n\t\t\t\t grid.add(arc2, 5, 1);\r\n\t\t\t\t arc2.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button\tsqrt =createButton(\"sqrt\");\r\n\t\t\t\t grid.add(sqrt, 5, 2); \r\n\t\t\t\t sqrt.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button\tdot =createButton(\".\");\r\n\t\t\t\t grid.add(dot, 1,3); \r\n\t\t\t\t dot.setStyle(\"-fx-background-color:pink\");\r\n\t\t         Button clearButton = createButton(\"∆\");\r\n\t\t\t\t Button tan=createButton(\"tan\");\r\n\t\t\t\t grid.add(tan,6,3);\r\n\t\t\t\t tan.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button sin=createButton(\"sin\");\r\n\t\t\t\t grid.add(sin,6,1);\r\n\t\t\t\t sin.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button log=createButton(\"log\");\r\n\t\t\t\t grid.add(log,6,0);\r\n\t\t\t\t log.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button cos=createButton(\"cos\");\r\n\t\t\t\t grid.add(cos,6,2);\r\n\t\t\t\t cos.setStyle(\"-fx-background-color:pink\");\r\n\t\t\t\t Button OFF=createButton(\"OFF\");\r\n\t\t\t\t grid.add(OFF,0,4,7,4);\r\n\t\t\t\t OFF.setStyle(\"-fx-background-color:pink\");\r\n\t\t         grid.add(clearButton,5, 0);\r\n\t\t         clearButton.setStyle(\"-fx-background-color:pink\");\r\n\t\t        displayField = createDisplayField();\r\n\t\t        displayField.setStyle(\"-fx-border-color:cyan\");\r\n\t\t        displayField.setPrefHeight(60);\r\n\t\t        BorderPane root = new BorderPane();\r\n\t\t        root.setPadding(new Insets(10));\r\n\t\t        root.setTop(displayField);\r\n\t\t        root.setCenter(grid);\r\n\t\t        clearButton.setOnAction(event -> v.set(\"\"));\r\n\t\t        OFF.setOnAction(event -> {\r\n\t\t    \t        System.exit(0);\r\n\t\t    \t});\r\n\t\t      arrow.setOnAction(event -> {\r\n\t\t\t  String s=displayField.getText();\r\n\r\n\t\t\t    if(frac){\r\n\t\t\t    \t\r\n\t\t\t    \t       if(s.charAt(s.length()-1)=='.')\r\n\t\t\t    \t        frac=false;}\r\n\t\t\t    \t       else v.set(s.substring(0,s.length()-1));\r\n\t\t\t    });\r\n\r\n\t\t\t\t\tequal.setOnAction(new EventHandler<ActionEvent>(){\r\n\t\t public void handle(ActionEvent t){\r\n\t\t Thread T=new Thread(new Runnable() {\r\n\r\n\t\t\t@Override\r\n\t\t\tpublic void run() {\r\n\r\n\t\t\t\t try{\r\n\t\t\t\t        \r\n\t\t\t\t\t\tString s=displayField.getText();\r\n\t\t\t\t  \t\tif(s.contains(\"log\"))\r\n\t\t\t\t        {\r\n\t\t\t\t    \t\r\n\t\t\t\t    \t  \t \r\n\t\t\t\t  \t\t\tString q=s.substring(3,s.length()); \r\n\t\t\t\t   \r\n\t\t\t\t    \t      String x= engine.eval(q).toString();\r\n\t\t\t\t    \t      double q1=Double.parseDouble(x);\r\n\t\t\t\t                v.set(Double.toString((int)Math.log(q1)));\r\n\t\t\t\t               \r\n\t\t\t\t        }\r\n\t\t\t\t        else if(s.contains(\"sin\"))\r\n\t\t\t\t        {String q=s.substring(3,s.length()); \r\n\t\t\t\t        \t String x= engine.eval(q).toString();\r\n\t\t\t\t   \t      double q1=Double.parseDouble(x);\r\n\t\t\t\t    \t \r\n\t\t\t\t                v.set(Double.toString( Math.sin(Math.toRadians(q1))));\r\n\t\t\t\t               \r\n\t\t\t\t        }                                                                              \r\n\t\t\t\t        else if(s.contains(\"tan\"))\r\n\t\t\t\t        { \r\n\t\t\t\t        \t  String q=s.substring(3,s.length()); \r\n\t\t\t\t        \t String x= engine.eval(q).toString();\r\n\t\t\t\t   \t      double q1=Double.parseDouble(x);\r\n\t\t\t\t               v.set(Double.toString( Math.tan(Math.toRadians(q1))));\r\n\t\t\t\t                \r\n\t\t\t\t        }\r\n\t\t\t\t        else if(s.contains(\"cos\"))\r\n\t\t\t\t        {String q=s.substring(3,s.length()); \r\n\t\t\t\t        \t String x= engine.eval(q).toString();\r\n\t\t\t\t   \t      double q1=Double.parseDouble(x);\r\n\t\t\t\t             v.set(Double.toString( Math.cos(Math.toRadians(q1))));                                    \r\n\t\t\t\t               \r\n\t\t\t\t        }\r\n\t\t\t\t \r\n\t\t\t\t        else   if( s.contains(\"-\")){\r\n\t\t\t\t \t        \r\n\t\t\t\tString x= engine.eval(s).toString();\r\n\t\t\t\t\t\t\t\tv.set(x);\r\n\t\t\t\t\t       }\r\n\t\t\t\t        else    if( s.contains(\"+\")){\r\n\t\t\t\t\t    \t  \r\n\t\t\t\t\t           String x= engine.eval(s).toString();\r\n\t\t\t\t\t           \t\t\r\n\t\t\t\t\t   \t\t\t\t\t\tv.set(x);\r\n\t\t\t\t\t           \t       }\r\n\t\t\t\t        else    if( s.contains(\"*\")){\r\n\t\t\t\t\t    \t  \r\n\t\t\t\t\t           String x= engine.eval(s).toString();\r\n\t\t\t\t\t           \r\n\t\t\t\t\t   \t\t\t\t\t\tv.set(x);\r\n\t\t\t\t\t           \t       }\r\n\t\t\t\t        else    if( s.contains(\"/\")){\r\n\t\t\t\t\t    \t  \r\n\r\n\t\t\t\t\t    \t  \r\n\t\t\t\t\t        \r\n\t\t\t\t\t           String x= engine.eval(s).toString();\r\n\t\t\t\t\t           \r\n\t\t\t\t\t   \t\t\t\t\t\t\r\n\t\t\t\t\t   \t\t\t\t\t\tv.set(x);\r\n\t\t\t\t\t           \t       }\r\n\t\t\t\t     \t\t else if(s.contains(\"^2\"))\r\n\t\t\t\t             {\r\n\t\t\t\t         \t  \t  String q=s.substring(0,s.indexOf(\"^2\")); \r\n\t\t\t\t                \t double  n=Double.parseDouble(q);\r\n\t\t\t\t                 v.set(Double.toString((n*n)));\r\n\t\t\t\t                 \r\n\t\t\t\t             }\r\n\t\t\t\t     \t else if(s.contains(\"sqrt\"))\r\n\t\t\t\t         {\r\n\t\t\t\t     \t  \t  String q=s.substring(4,s.length()); \r\n\t\t\t\t            \t double  n=Double.parseDouble(q);\r\n\t\t\t\t             v.set(Double.toString(Math.sqrt(n)));\r\n\t\t\t\t             \r\n\t\t\t\t         }\r\n\r\n\t\t\t\t    \t\r\n\t\t\t\t     \telse if(s.contains(\"%\")) {\r\n\t\t\t\t\t\r\n\t\t\t\t     \t\t  String q=s.substring(0,s.indexOf(\"%\")); \r\n\t\t\t\t \t double  n=Double.parseDouble(q);\r\n\t\t\t\t  v.set(Double.toString(n/100));}\r\n\t\t\t\t     \r\n\t\t\t\t     } \r\n\t\t\t\t    \r\n\t\t\t\t    catch (Exception ex)\r\n\t\t\t\t    {\r\n\t\t\t\t            ex.printStackTrace();\r\n\t\t\t\t    }\r\n\t\t\t\t    }\r\n\t\t\t});\r\n\t\t\t\tT.start();\t}\r\n\t\t        \r\n\r\n\t\t});\r\n\t\t        Scene scene = new Scene(root, 365, 300);\r\n\r\n\t\t        primaryStage.setScene(scene);\r\n\t\t        primaryStage.setResizable(false);\r\n\t\t        primaryStage.show();\r\n\t\t    }\r\n\t\t     private Button createNumberButton(String number) {\r\n\t\t        Button button = createButton(number);\r\n\t\t        button.setOnAction(new NumberButtonHandler(number));\r\n\t\t        return button ;\r\n\t\t    }\r\n\t\t    private Button createButton(String text) {\r\n\t\t        Button button = new Button(text);\r\n\t\t        button.setMaxSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);\r\n\t\t        GridPane.setFillHeight(button, true);\r\n\t\t        GridPane.setFillWidth(button, true);\r\n\t\t        GridPane.setHgrow(button, Priority.ALWAYS);\r\n\t\t        GridPane.setVgrow(button, Priority.ALWAYS);\r\n\t\t       button.setOnAction(new NumberButtonHandler(text));\r\n\t\t        return button ;\r\n\t\t    }\r\n\t\t    private GridPane createGrid() {\r\n\t\t        GridPane grid = new GridPane();\r\n\t\t        grid.setAlignment(Pos.CENTER);\r\n\t\t        grid.setHgap(5);\r\n\t\t        grid.setVgap(5);\r\n\t\t        grid.setPadding(new Insets(10));\r\n\t\t        return grid;\r\n\t\t    }\r\n\r\n\t\t    private TextField createDisplayField() {\r\n\t\t        TextField displayField = new TextField();\r\n\t\t        displayField.textProperty().bind(  v);\r\n\t\t        \r\n\t\t        displayField.setEditable(false);\r\n\t\t        displayField.setAlignment(Pos.CENTER_RIGHT);\r\n\t\t        return displayField;\r\n\t\t    }\r\n\t\t    public static void main(String[] args) {\r\n\t\t        launch(args);\r\n\t\t    }\r\n\r\n}"}}