|
@@ -0,0 +1,165 @@
|
|
1
|
+package rocks.zipcode.yesoda;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+import javafx.application.Application;
|
|
5
|
+import javafx.geometry.Insets;
|
|
6
|
+import javafx.geometry.Pos;
|
|
7
|
+import javafx.scene.Parent;
|
|
8
|
+import javafx.scene.Scene;
|
|
9
|
+import javafx.scene.control.*;
|
|
10
|
+import javafx.scene.layout.VBox;
|
|
11
|
+import javafx.stage.Stage;
|
|
12
|
+import javafx.scene.layout.FlowPane;
|
|
13
|
+import rocks.zipcode.yesoda.bank.Bank;
|
|
14
|
+
|
|
15
|
+/**
|
|
16
|
+ * @author ZipCodeWilmington
|
|
17
|
+ */
|
|
18
|
+public class CashMachineApp extends Application {
|
|
19
|
+
|
|
20
|
+ private TextField fieldID = new TextField();
|
|
21
|
+ private TextField fieldWithdraw = new TextField();
|
|
22
|
+ private CashMachine cashMachine = new CashMachine(new Bank());
|
|
23
|
+ Button btnDeposit = new Button();
|
|
24
|
+ Button btnWithdraw = new Button();
|
|
25
|
+
|
|
26
|
+ private Parent createContent() {
|
|
27
|
+ VBox vbox = new VBox(10);
|
|
28
|
+ Label mainLabel = new Label();
|
|
29
|
+ mainLabel.setText("Welcome to ZIP CODE \n CASH MACHINE");
|
|
30
|
+ vbox.setPrefSize(600, 600);
|
|
31
|
+ String strTemp;
|
|
32
|
+
|
|
33
|
+ TextArea areaInfo = new TextArea();
|
|
34
|
+
|
|
35
|
+ Button btnSubmit = new Button("Enter Your AccountID");
|
|
36
|
+ btnSubmit.setOnAction(e -> {
|
|
37
|
+
|
|
38
|
+ int id = Integer.parseInt(fieldID.getText());
|
|
39
|
+ cashMachine.login(id);
|
|
40
|
+
|
|
41
|
+ if (cashMachine.toString().toString().equalsIgnoreCase("1")) {
|
|
42
|
+ showAlertWithHeaderText("ERROR","" ,"Enter a valid Account number - 1000 or 2000 ");
|
|
43
|
+ } else {
|
|
44
|
+ areaInfo.setText(cashMachine.toString());
|
|
45
|
+ onValidIDButtonIdClick(btnSubmit);
|
|
46
|
+ }
|
|
47
|
+ });
|
|
48
|
+
|
|
49
|
+ Button btnParentExit = new Button("Exit");
|
|
50
|
+ btnParentExit.setOnAction(e -> {
|
|
51
|
+ cashMachine.exit();
|
|
52
|
+
|
|
53
|
+ //areaInfo.setText(cashMachine.toString());
|
|
54
|
+ });
|
|
55
|
+
|
|
56
|
+ FlowPane flowpane = new FlowPane();
|
|
57
|
+
|
|
58
|
+ mainLabel.setLayoutX(100);
|
|
59
|
+ mainLabel.setLayoutY(100);
|
|
60
|
+ vbox.setAlignment(Pos.TOP_CENTER);
|
|
61
|
+ fieldID.setMaxSize( 200, 20);
|
|
62
|
+ vbox.getChildren().addAll(mainLabel, btnSubmit, fieldID, flowpane, btnParentExit);
|
|
63
|
+ return vbox;
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+ public void onValidIDButtonIdClick(Button btnSubmit) {
|
|
68
|
+ FlowPane flow = new FlowPane();
|
|
69
|
+ Scene secondScene = new Scene(flow, 600, 600);
|
|
70
|
+ Stage secondStage = new Stage();
|
|
71
|
+
|
|
72
|
+ TextField fieldDeposit = new TextField();
|
|
73
|
+ flow.setAlignment(Pos.TOP_LEFT);
|
|
74
|
+ //fieldDeposit.setText("Enter the Amount to Deposit - ");
|
|
75
|
+ flow.setAlignment(Pos.TOP_RIGHT);
|
|
76
|
+ flow.getChildren().add(fieldDeposit);
|
|
77
|
+ Button btnDeposit = new Button("Deposit");
|
|
78
|
+ flow.getChildren().add(btnDeposit);
|
|
79
|
+ TextField fieldWithDraw = new TextField();
|
|
80
|
+ flow.getChildren().add(fieldWithDraw);
|
|
81
|
+ Button btnWithdraw = new Button("WithDraw");
|
|
82
|
+ flow.getChildren().add(btnWithdraw);
|
|
83
|
+ TextArea areaInfo = new TextArea();
|
|
84
|
+ Button btnExit = exitButtonDisplay(secondStage );
|
|
85
|
+ flow.setPadding(new Insets(10, 10, 10, 10));
|
|
86
|
+ flow.setStyle("-fx-background-color: DAE6F3;");
|
|
87
|
+ flow.setHgap(10);
|
|
88
|
+ flow.getChildren().add(btnExit );
|
|
89
|
+ flow.getChildren().add (areaInfo);
|
|
90
|
+ secondStage.setScene(secondScene); // set the scene
|
|
91
|
+ secondStage.setTitle(" Please select the Bank Operation you want to perform ");
|
|
92
|
+ secondStage.show();
|
|
93
|
+ // close the first stage (Window)
|
|
94
|
+
|
|
95
|
+ btnDeposit.setOnAction(e -> {
|
|
96
|
+ int amount = Integer.parseInt(fieldDeposit.getText());
|
|
97
|
+ cashMachine.deposit(amount);
|
|
98
|
+
|
|
99
|
+ showAlertWithHeaderText("Deposit Success","" ,"Deposited Amount Successfully");
|
|
100
|
+ areaInfo.setPrefRowCount(8);
|
|
101
|
+ areaInfo.setText("Amount deposited now - " + amount + " \n ----Account Summary ---- \n" + cashMachine.toString());
|
|
102
|
+ areaInfo.setText(cashMachine.toString());
|
|
103
|
+ //cashMachine.toString();
|
|
104
|
+ }) ;
|
|
105
|
+
|
|
106
|
+ btnWithdraw.setOnAction(e -> {
|
|
107
|
+ int amount = Integer.parseInt(fieldWithDraw .getText());
|
|
108
|
+ cashMachine.withdraw(amount);
|
|
109
|
+ showAlertWithHeaderText("Withdraw","" ,"Withdraw Amount Successfully");
|
|
110
|
+ areaInfo.setText(cashMachine.toString());
|
|
111
|
+ });
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ /* public void onDepositButtonClick()
|
|
119
|
+ {
|
|
120
|
+ Button btnDeposit = new Button("Deposit");
|
|
121
|
+ btnDeposit.setOnAction(e -> {
|
|
122
|
+ int amount = Integer.parseInt(fieldID.getText());
|
|
123
|
+ cashMachine.deposit(amount);
|
|
124
|
+
|
|
125
|
+ // areaInfo.setText(cashMachine.toString());
|
|
126
|
+ });
|
|
127
|
+ }*/
|
|
128
|
+
|
|
129
|
+ public Button exitButtonDisplay(Stage stage) {
|
|
130
|
+
|
|
131
|
+ Button btnExit = new Button("Exit");
|
|
132
|
+ btnExit.setOnAction(e ->
|
|
133
|
+
|
|
134
|
+ {
|
|
135
|
+ cashMachine.exit();
|
|
136
|
+ stage.close();
|
|
137
|
+
|
|
138
|
+ //areaInfo.setText(cashMachine.toString());
|
|
139
|
+ });
|
|
140
|
+ return btnExit;
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ private void showAlertWithHeaderText(String title,String headertxt,String content ) {
|
|
146
|
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
147
|
+ alert.setTitle(title);
|
|
148
|
+ alert.setHeaderText(headertxt);
|
|
149
|
+ alert.setContentText(content);
|
|
150
|
+
|
|
151
|
+ alert.showAndWait();
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+ @Override
|
|
156
|
+ public void start(Stage stage) throws Exception {
|
|
157
|
+ stage.setScene(new Scene(createContent()));
|
|
158
|
+ stage.show();
|
|
159
|
+ //stage.close();
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ public static void main(String[] args) {
|
|
163
|
+ launch(args);
|
|
164
|
+ }
|
|
165
|
+}
|