|
@@ -1,5 +1,7 @@
|
1
|
1
|
package rocks.zipcode.atm;
|
2
|
2
|
|
|
3
|
+import javafx.geometry.Pos;
|
|
4
|
+import javafx.scene.layout.GridPane;
|
3
|
5
|
import rocks.zipcode.atm.bank.Bank;
|
4
|
6
|
import javafx.application.Application;
|
5
|
7
|
import javafx.scene.Parent;
|
|
@@ -7,71 +9,124 @@ import javafx.scene.Scene;
|
7
|
9
|
import javafx.scene.control.Button;
|
8
|
10
|
import javafx.scene.control.TextArea;
|
9
|
11
|
import javafx.scene.control.TextField;
|
10
|
|
-import javafx.scene.layout.VBox;
|
11
|
12
|
import javafx.stage.Stage;
|
12
|
|
-import javafx.scene.layout.FlowPane;
|
|
13
|
+import javafx.scene.paint.Color;
|
13
|
14
|
|
14
|
15
|
/**
|
15
|
16
|
* @author ZipCodeWilmington
|
16
|
17
|
*/
|
17
|
18
|
public class CashMachineApp extends Application {
|
|
19
|
+ Color blue = Color.rgb(0,0,255);
|
18
|
20
|
|
19
|
|
- private TextField field = new TextField();
|
20
|
21
|
private CashMachine cashMachine = new CashMachine(new Bank());
|
21
|
22
|
|
|
23
|
+ private TextField setAccountIdField = new TextField();
|
|
24
|
+ private TextField setDepositField = new TextField();
|
|
25
|
+ private TextField setWithdrawField = new TextField();
|
|
26
|
+
|
22
|
27
|
private Parent createContent() {
|
23
|
|
- VBox vbox = new VBox(10);
|
24
|
|
- vbox.setPrefSize(600, 600);
|
|
28
|
+ setAccountIdField.setMinSize(250, 40);
|
|
29
|
+ setDepositField.setMinSize(250, 40);
|
|
30
|
+ setWithdrawField.setMinSize(250, 40);
|
25
|
31
|
|
26
|
|
- TextArea areaInfo = new TextArea();
|
|
32
|
+ GridPane gridPane = new GridPane();
|
|
33
|
+ gridPane.setPrefSize(500, 400);
|
|
34
|
+ gridPane.setAlignment(Pos.CENTER);
|
|
35
|
+ gridPane.setStyle("-fx-background-color: Green;");
|
27
|
36
|
|
28
|
|
- Button btnSubmit = new Button("Set Account ID");
|
29
|
|
- btnSubmit.setOnAction(e -> {
|
30
|
|
- int id = Integer.parseInt(field.getText());
|
31
|
|
- cashMachine.login(id);
|
|
37
|
+ TextArea areaInfo = new TextArea();
|
|
38
|
+ areaInfo.setMaxSize(250, 160);
|
32
|
39
|
|
33
|
|
- areaInfo.setText(cashMachine.toString());
|
34
|
|
- });
|
35
|
40
|
|
36
|
41
|
Button btnDeposit = new Button("Deposit");
|
|
42
|
+ btnDeposit.setMinSize(250, 40);
|
|
43
|
+ btnDeposit.setTextFill(blue);
|
|
44
|
+ btnDeposit.setDisable(true);
|
37
|
45
|
btnDeposit.setOnAction(e -> {
|
38
|
|
- int amount = Integer.parseInt(field.getText());
|
|
46
|
+ float amount = Float.parseFloat(setWithdrawField.getText());
|
39
|
47
|
cashMachine.deposit(amount);
|
40
|
|
-
|
41
|
48
|
areaInfo.setText(cashMachine.toString());
|
42
|
49
|
});
|
43
|
50
|
|
44
|
51
|
Button btnWithdraw = new Button("Withdraw");
|
|
52
|
+ btnWithdraw.setMinSize(250, 40);
|
|
53
|
+ btnWithdraw.setTextFill(blue);
|
|
54
|
+ btnWithdraw.setDisable(true);
|
45
|
55
|
btnWithdraw.setOnAction(e -> {
|
46
|
|
- int amount = Integer.parseInt(field.getText());
|
|
56
|
+ float amount = Float.parseFloat(setWithdrawField.getText());
|
47
|
57
|
cashMachine.withdraw(amount);
|
48
|
|
-
|
49
|
58
|
areaInfo.setText(cashMachine.toString());
|
50
|
59
|
});
|
51
|
60
|
|
52
|
61
|
Button btnExit = new Button("Exit");
|
|
62
|
+ btnExit.setMinSize(250, 160);
|
|
63
|
+ btnExit.setTextFill(blue);
|
|
64
|
+ btnExit.setDisable(true);
|
53
|
65
|
btnExit.setOnAction(e -> {
|
|
66
|
+ btnDeposit.setDisable(true);
|
|
67
|
+ btnWithdraw.setDisable(true);
|
|
68
|
+ btnExit.setDisable(true);
|
|
69
|
+ resetOnExit();
|
54
|
70
|
cashMachine.exit();
|
|
71
|
+ areaInfo.setText(cashMachine.toString());
|
|
72
|
+ });
|
|
73
|
+
|
|
74
|
+ Button btnSubmit = new Button("Set Account ID");
|
|
75
|
+ btnSubmit.setMinSize(250, 40);
|
|
76
|
+ btnSubmit.setTextFill(blue);
|
|
77
|
+ btnSubmit.setOnAction(e -> {
|
|
78
|
+ int id = Integer.parseInt(setAccountIdField.getText());
|
|
79
|
+ if (isValidId(id)){
|
|
80
|
+ btnDeposit.setDisable(false);
|
|
81
|
+ btnWithdraw.setDisable(false);
|
|
82
|
+ btnExit.setDisable(false);
|
|
83
|
+ }
|
|
84
|
+ else {
|
|
85
|
+ btnDeposit.setDisable(true);
|
|
86
|
+ btnWithdraw.setDisable(true);
|
|
87
|
+ btnExit.setDisable(true);
|
|
88
|
+ }
|
|
89
|
+ cashMachine.login(id);
|
55
|
90
|
|
56
|
91
|
areaInfo.setText(cashMachine.toString());
|
57
|
92
|
});
|
58
|
93
|
|
59
|
|
- FlowPane flowpane = new FlowPane();
|
60
|
94
|
|
61
|
|
- flowpane.getChildren().add(btnSubmit);
|
62
|
|
- flowpane.getChildren().add(btnDeposit);
|
63
|
|
- flowpane.getChildren().add(btnWithdraw);
|
64
|
|
- flowpane.getChildren().add(btnExit);
|
65
|
|
- vbox.getChildren().addAll(field, flowpane, areaInfo);
|
66
|
|
- return vbox;
|
|
95
|
+ GridPane.setConstraints(btnSubmit, 0, 0);
|
|
96
|
+ GridPane.setConstraints(btnDeposit, 0, 1);
|
|
97
|
+ GridPane.setConstraints(btnWithdraw, 0, 2);
|
|
98
|
+ GridPane.setConstraints(btnExit, 0, 3);
|
|
99
|
+ GridPane.setConstraints(setAccountIdField, 1, 0);
|
|
100
|
+ setWithdrawField.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
|
101
|
+ GridPane.setConstraints(setWithdrawField, 1, 1, 1, 2);
|
|
102
|
+ GridPane.setConstraints(areaInfo, 1, 3);
|
|
103
|
+ gridPane.getChildren().addAll(btnSubmit, btnDeposit, btnWithdraw, btnExit,
|
|
104
|
+ setAccountIdField, setWithdrawField, areaInfo);
|
|
105
|
+ return gridPane;
|
67
|
106
|
}
|
68
|
107
|
|
69
|
108
|
@Override
|
70
|
109
|
public void start(Stage stage) throws Exception {
|
71
|
110
|
stage.setScene(new Scene(createContent()));
|
|
111
|
+ stage.setTitle("Zip Code ATM");
|
72
|
112
|
stage.show();
|
73
|
113
|
}
|
74
|
114
|
|
|
115
|
+ public boolean isValidId(int id){
|
|
116
|
+ if (cashMachine.isValidId(id)) {
|
|
117
|
+ return true;
|
|
118
|
+ }
|
|
119
|
+ else {
|
|
120
|
+ return false;
|
|
121
|
+ }
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ public void resetOnExit(){
|
|
125
|
+ setAccountIdField.clear();
|
|
126
|
+ setDepositField.clear();
|
|
127
|
+ setWithdrawField.clear();
|
|
128
|
+ }
|
|
129
|
+
|
75
|
130
|
public static void main(String[] args) {
|
76
|
131
|
launch(args);
|
77
|
132
|
}
|