-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorView.java
More file actions
61 lines (46 loc) · 1.88 KB
/
Copy pathCalculatorView.java
File metadata and controls
61 lines (46 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mvc;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class CalculatorView extends BorderPane {
Button button1 = new Button("1");
Button button2 = new Button("2");
Button button0 = new Button("0");
Button button3 = new Button("3");
Button button4 = new Button("4");
Button button5 = new Button("5");
Button button6 = new Button("6");
Button button7 = new Button("7");
Button button8 = new Button("8");
Button button9 = new Button("9");
Button addButton = new Button("+");
Button subtractButton = new Button("-");
Button multiplyButton = new Button("*");
Button divideButton = new Button("/");
Button equalsButton = new Button("=");
Button clearButton = new Button("C");
Button clearEntryButton = new Button("CE");
private TextField inputField;
public CalculatorView() {
inputField = new TextField();
inputField.setEditable(false);
HBox topRow = new HBox(5, button7, button8, button9, divideButton);
HBox middleRow = new HBox(5, button4, button5, button6, multiplyButton);
HBox bottomRow = new HBox(5, button1, button2, button3, subtractButton);
HBox lastRow = new HBox(5, clearEntryButton, button0, clearButton, addButton);
HBox resultRow = new HBox(5, equalsButton);
VBox buttonBox = new VBox(6, topRow, middleRow, bottomRow, lastRow, resultRow);
setCenter(buttonBox);
setTop(inputField);
BorderPane.setAlignment(inputField, Pos.CENTER);
}
public String getInputText() {
return inputField.getText();
}
public void setInputText(String text) {
inputField.setText(text);
}
}