CHU1TA26 vor 6 Jahren
Ursprung
Commit
e6bfa35d1e

+ 9
- 2
pom.xml Datei anzeigen

13
                 <groupId>org.apache.maven.plugins</groupId>
13
                 <groupId>org.apache.maven.plugins</groupId>
14
                 <artifactId>maven-compiler-plugin</artifactId>
14
                 <artifactId>maven-compiler-plugin</artifactId>
15
                 <configuration>
15
                 <configuration>
16
-                    <source>1.7</source>
17
-                    <target>1.7</target>
16
+                    <source>1.8</source>
17
+                    <target>1.8</target>
18
                 </configuration>
18
                 </configuration>
19
             </plugin>
19
             </plugin>
20
         </plugins>
20
         </plugins>
25
             <artifactId>junit</artifactId>
25
             <artifactId>junit</artifactId>
26
             <version>4.0</version>
26
             <version>4.0</version>
27
         </dependency>
27
         </dependency>
28
+        <!-- https://mvnrepository.com/artifact/com.zenjava/javafx-maven-plugin -->
29
+        <dependency>
30
+            <groupId>com.zenjava</groupId>
31
+            <artifactId>javafx-maven-plugin</artifactId>
32
+            <version>8.8.3</version>
33
+        </dependency>
34
+
28
     </dependencies>
35
     </dependencies>
29
 
36
 
30
 
37
 

+ 16
- 4
src/main/java/rocks/zipcode/calcskin/CalcEngine.java Datei anzeigen

6
     }
6
     }
7
 
7
 
8
     public double add(double v, double v1) {
8
     public double add(double v, double v1) {
9
-        return Double.NaN;
9
+        return v + v1;
10
     }
10
     }
11
 
11
 
12
     public double subtract(double v, double v1) {
12
     public double subtract(double v, double v1) {
13
-        return Double.NaN;
13
+        return v-v1;
14
     }
14
     }
15
 
15
 
16
     public double multiply(double v, double v1) {
16
     public double multiply(double v, double v1) {
17
-        return Double.NaN;
17
+        return v * v1;
18
     }
18
     }
19
 
19
 
20
     public double divide(double v, double v1) {
20
     public double divide(double v, double v1) {
21
-        return Double.NaN;
21
+        return v/v1;
22
     }
22
     }
23
+    public double square ( double v){
24
+        return Math.pow(v , 2.0);
25
+    }
26
+    public double root(double v){return Math.sqrt(v); }
27
+
28
+    public double expo ( double v , double v1){
29
+        return Math.pow(v,v1);
30
+    }
31
+
32
+
33
+
34
+
23
 }
35
 }

+ 16
- 11
src/main/java/rocks/zipcode/calcskin/CalcSkin.java Datei anzeigen

12
 import javafx.scene.layout.*;
12
 import javafx.scene.layout.*;
13
 import javafx.stage.Stage;
13
 import javafx.stage.Stage;
14
 import javafx.stage.StageStyle;
14
 import javafx.stage.StageStyle;
15
-import rocks.zipcode.calcskin.CalcEngine;
16
 
15
 
17
 import java.util.HashMap;
16
 import java.util.HashMap;
18
 import java.util.Map;
17
 import java.util.Map;
24
         launch(args);
23
         launch(args);
25
     }
24
     }
26
     private static final String[][] template = {
25
     private static final String[][] template = {
27
-            { "7", "8", "9", "/" },
28
-            { "4", "5", "6", "*" },
29
-            { "1", "2", "3", "-" },
26
+            { "7", "8", "9", "/", "x^2" },
27
+            { "4", "5", "6", "*",  "rt" },
28
+            { "1", "2", "3", "-",  "x^y" },
30
             { "0", "c", "=", "+" }
29
             { "0", "c", "=", "+" }
31
     };
30
     };
32
 
31
 
36
     private DoubleProperty currentValue = new SimpleDoubleProperty();
35
     private DoubleProperty currentValue = new SimpleDoubleProperty();
37
     private CalcEngine calcEngine = new CalcEngine();
36
     private CalcEngine calcEngine = new CalcEngine();
38
 
37
 
39
-    private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
38
+    private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, SQUARE, ROOT, EXPO }
40
 
39
 
41
     private Op curOp   = Op.NOOP;
40
     private Op curOp   = Op.NOOP;
42
     private Op stackOp = Op.NOOP;
41
     private Op stackOp = Op.NOOP;
60
     private VBox createLayout(TextField screen, TilePane buttons) {
59
     private VBox createLayout(TextField screen, TilePane buttons) {
61
         final VBox layout = new VBox(20);
60
         final VBox layout = new VBox(20);
62
         layout.setAlignment(Pos.CENTER);
61
         layout.setAlignment(Pos.CENTER);
63
-        layout.setStyle("-fx-background-color: silver; -fx-padding: 20; -fx-font-size: 20;");
62
+        layout.setStyle("-fx-background-color: green; -fx-padding: 20; -fx-font-size: 20;");
64
         layout.getChildren().setAll(screen, buttons);
63
         layout.getChildren().setAll(screen, buttons);
65
         handleAccelerators(layout);
64
         handleAccelerators(layout);
66
         screen.prefWidthProperty().bind(buttons.widthProperty());
65
         screen.prefWidthProperty().bind(buttons.widthProperty());
81
 
80
 
82
     private TextField createScreen() {
81
     private TextField createScreen() {
83
         final TextField screen = new TextField();
82
         final TextField screen = new TextField();
84
-        screen.setStyle("-fx-background-color: aquamarine;");
83
+        screen.setStyle("-fx-background-color: black;");
85
         screen.setAlignment(Pos.CENTER_RIGHT);
84
         screen.setAlignment(Pos.CENTER_RIGHT);
86
         screen.setEditable(false);
85
         screen.setEditable(false);
87
         screen.textProperty().bind(Bindings.format("%.0f", currentValue));
86
         screen.textProperty().bind(Bindings.format("%.0f", currentValue));
127
             case "-": triggerOp.set(Op.SUBTRACT); break;
126
             case "-": triggerOp.set(Op.SUBTRACT); break;
128
             case "*": triggerOp.set(Op.MULTIPLY); break;
127
             case "*": triggerOp.set(Op.MULTIPLY); break;
129
             case "/": triggerOp.set(Op.DIVIDE);   break;
128
             case "/": triggerOp.set(Op.DIVIDE);   break;
129
+            case "x^2": triggerOp.set(Op.SQUARE);   break;
130
+            case "rt": triggerOp.set(Op.ROOT);   break;
131
+            case "x^y": triggerOp.set(Op.EXPO);   break;
130
         }
132
         }
131
         return triggerOp;
133
         return triggerOp;
132
     }
134
     }
133
 
135
 
134
     private void makeOperandButton(Button button, final ObjectProperty<Op> triggerOp) {
136
     private void makeOperandButton(Button button, final ObjectProperty<Op> triggerOp) {
135
-        button.setStyle("-fx-base: lightgray;");
137
+        button.setStyle("-fx-base: lightblue;");
136
         button.setOnAction(new EventHandler<ActionEvent>() {
138
         button.setOnAction(new EventHandler<ActionEvent>() {
137
             @Override
139
             @Override
138
             public void handle(ActionEvent actionEvent) {
140
             public void handle(ActionEvent actionEvent) {
143
 
145
 
144
     private Button makeStandardButton(String s) {
146
     private Button makeStandardButton(String s) {
145
         Button button = new Button(s);
147
         Button button = new Button(s);
146
-        button.setStyle("-fx-base: beige;");
148
+        button.setStyle("-fx-base: pink;");
147
         accelerators.put(s, button);
149
         accelerators.put(s, button);
148
         button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
150
         button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
149
         return button;
151
         return button;
166
     }
168
     }
167
 
169
 
168
     private void makeClearButton(Button button) {
170
     private void makeClearButton(Button button) {
169
-        button.setStyle("-fx-base: mistyrose;");
171
+        button.setStyle("-fx-base: orange;");
170
         button.setOnAction(new EventHandler<ActionEvent>() {
172
         button.setOnAction(new EventHandler<ActionEvent>() {
171
             @Override
173
             @Override
172
             public void handle(ActionEvent actionEvent) {
174
             public void handle(ActionEvent actionEvent) {
176
     }
178
     }
177
 
179
 
178
     private void makeEqualsButton(Button button) {
180
     private void makeEqualsButton(Button button) {
179
-        button.setStyle("-fx-base: ghostwhite;");
181
+        button.setStyle("-fx-base: violet;");
180
         button.setOnAction(new EventHandler<ActionEvent>() {
182
         button.setOnAction(new EventHandler<ActionEvent>() {
181
             @Override
183
             @Override
182
             public void handle(ActionEvent actionEvent) {
184
             public void handle(ActionEvent actionEvent) {
185
                     case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
187
                     case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
186
                     case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
188
                     case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
187
                     case DIVIDE:   currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
189
                     case DIVIDE:   currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
190
+                    case ROOT:   currentValue.set(calcEngine.root( currentValue.get())); break;
191
+                    case SQUARE:   currentValue.set(calcEngine.square( currentValue.get())); break;
192
+                    case EXPO:   currentValue.set(calcEngine.expo(previousValue.get(), currentValue.get())); break;
188
                 }
193
                 }
189
             }
194
             }
190
         });
195
         });