|
@@ -24,10 +24,10 @@ public class CalcSkin extends Application {
|
24
|
24
|
launch(args);
|
25
|
25
|
}
|
26
|
26
|
private static final String[][] template = {
|
27
|
|
- { "7", "8", "9", "/" },
|
28
|
|
- { "4", "5", "6", "*" },
|
29
|
|
- { "1", "2", "3", "-" },
|
30
|
|
- { "0", "c", "=", "+" }
|
|
27
|
+ { "7", "8", "9", "/", "x^2"},
|
|
28
|
+ { "4", "5", "6", "*", "sqrt"},
|
|
29
|
+ { "1", "2", "3", "-", ""},
|
|
30
|
+ { "0", "c", "=", "+"}
|
31
|
31
|
};
|
32
|
32
|
|
33
|
33
|
private final Map<String, Button> accelerators = new HashMap<>();
|
|
@@ -84,14 +84,14 @@ public class CalcSkin extends Application {
|
84
|
84
|
screen.setStyle("-fx-background-color: aquamarine;");
|
85
|
85
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
86
|
screen.setEditable(false);
|
87
|
|
- screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
87
|
+ screen.textProperty().bind(Bindings.format("%.3f", currentValue));
|
88
|
88
|
return screen;
|
89
|
89
|
}
|
90
|
90
|
|
91
|
91
|
private TilePane createButtons() {
|
92
|
92
|
TilePane buttons = new TilePane();
|
93
|
|
- buttons.setVgap(7);
|
94
|
|
- buttons.setHgap(7);
|
|
93
|
+ buttons.setVgap(10);
|
|
94
|
+ buttons.setHgap(10);
|
95
|
95
|
buttons.setPrefColumns(template[0].length);
|
96
|
96
|
for (String[] r: template) {
|
97
|
97
|
for (String s: r) {
|
|
@@ -114,6 +114,12 @@ public class CalcSkin extends Application {
|
114
|
114
|
makeClearButton(button);
|
115
|
115
|
} else if ("=".equals(s)) {
|
116
|
116
|
makeEqualsButton(button);
|
|
117
|
+ } else if("x^2".equals(s)){
|
|
118
|
+ makeSquareButton(button);
|
|
119
|
+ } else if("sqrt".equals(s)){
|
|
120
|
+ makeSqrtButton(button);
|
|
121
|
+ } else if("1/x".equals(s)){
|
|
122
|
+ makeInverseButton(button);
|
117
|
123
|
}
|
118
|
124
|
}
|
119
|
125
|
|
|
@@ -175,6 +181,39 @@ public class CalcSkin extends Application {
|
175
|
181
|
});
|
176
|
182
|
}
|
177
|
183
|
|
|
184
|
+ private void makeSquareButton(Button button){
|
|
185
|
+ button.setStyle("-fx-base: ghostwhite;");
|
|
186
|
+ button.setOnAction(new EventHandler<ActionEvent>() {
|
|
187
|
+ @Override
|
|
188
|
+ public void handle(ActionEvent actionEvent) {
|
|
189
|
+ currentValue.set(calcEngine.square(currentValue.get()));
|
|
190
|
+ }
|
|
191
|
+ });
|
|
192
|
+
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ private void makeInverseButton(Button button){
|
|
196
|
+ button.setStyle("-fx-base: ghostwhite;");
|
|
197
|
+ button.setOnAction(new EventHandler<ActionEvent>() {
|
|
198
|
+ @Override
|
|
199
|
+ public void handle(ActionEvent actionEvent) {
|
|
200
|
+ currentValue.set(calcEngine.inverse(currentValue.get()));
|
|
201
|
+ }
|
|
202
|
+ });
|
|
203
|
+
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ private void makeSqrtButton(Button button){
|
|
207
|
+ button.setStyle("-fx-base: ghostwhite;");
|
|
208
|
+ button.setOnAction(new EventHandler<ActionEvent>() {
|
|
209
|
+ @Override
|
|
210
|
+ public void handle(ActionEvent actionEvent) {
|
|
211
|
+ currentValue.set(calcEngine.sqrt(currentValue.get()));
|
|
212
|
+ }
|
|
213
|
+ });
|
|
214
|
+
|
|
215
|
+ }
|
|
216
|
+
|
178
|
217
|
private void makeEqualsButton(Button button) {
|
179
|
218
|
button.setStyle("-fx-base: ghostwhite;");
|
180
|
219
|
button.setOnAction(new EventHandler<ActionEvent>() {
|