|
@@ -1,17 +1,20 @@
|
1
|
1
|
package rocks.zipcode.atm;
|
2
|
2
|
|
|
3
|
+import javafx.geometry.Insets;
|
|
4
|
+import javafx.geometry.Pos;
|
|
5
|
+import javafx.scene.control.*;
|
|
6
|
+import javafx.scene.layout.GridPane;
|
3
|
7
|
import javafx.scene.text.Text;
|
4
|
8
|
import rocks.zipcode.atm.bank.Bank;
|
5
|
9
|
import javafx.application.Application;
|
6
|
10
|
import javafx.scene.Parent;
|
7
|
11
|
import javafx.scene.Scene;
|
8
|
|
-import javafx.scene.control.Button;
|
9
|
|
-import javafx.scene.control.TextArea;
|
10
|
|
-import javafx.scene.control.TextField;
|
11
|
12
|
import javafx.scene.layout.VBox;
|
12
|
13
|
import javafx.stage.Stage;
|
13
|
14
|
import javafx.scene.layout.FlowPane;
|
14
|
15
|
|
|
16
|
+import java.util.ArrayList;
|
|
17
|
+
|
15
|
18
|
/**
|
16
|
19
|
* @author ZipCodeWilmington
|
17
|
20
|
*/
|
|
@@ -19,100 +22,112 @@ public class CashMachineApp extends Application {
|
19
|
22
|
|
20
|
23
|
private TextField field = new TextField();
|
21
|
24
|
private CashMachine cashMachine = new CashMachine(new Bank());
|
22
|
|
- private TextField amountField = new TextField();
|
23
|
25
|
|
24
|
26
|
private Parent createContent() {
|
25
|
|
- field.setPromptText("Enter your account ID");
|
26
|
27
|
field.setFocusTraversable(false);
|
27
|
|
-
|
|
28
|
+ field.setPromptText("Enter Account ID");
|
|
29
|
+ FlowPane flowpane = new FlowPane();
|
28
|
30
|
VBox vbox = new VBox(10);
|
29
|
31
|
vbox.setPrefSize(600, 600);
|
30
|
32
|
|
31
|
|
- Text areaInfo = new Text();
|
32
|
|
- areaInfo.setVisible(false);
|
33
|
|
-
|
34
|
|
- FlowPane flowpane = new FlowPane();
|
|
33
|
+ TextArea areaInfo = new TextArea();
|
35
|
34
|
|
36
|
|
- Button btnSubmit = new Button("Login");
|
37
|
|
- btnSubmit.setOnAction(e -> {
|
38
|
|
- int id = Integer.parseInt(field.getText());
|
39
|
|
- cashMachine.login(id);
|
40
|
|
- });
|
41
|
|
-//
|
42
|
|
-// String[] acctFields;
|
43
|
|
-// acctFields = String.valueOf(areaInfo).split("\n");
|
|
35
|
+ GridPane gridPane = new GridPane();
|
|
36
|
+ gridPane.setAlignment(Pos.CENTER_LEFT);
|
|
37
|
+ gridPane.setVgap(5);
|
|
38
|
+ gridPane.setHgap(5);
|
|
39
|
+ Text account = new Text();
|
|
40
|
+ Text name = new Text();
|
|
41
|
+ Text email = new Text();
|
|
42
|
+ Text balance = new Text();
|
44
|
43
|
|
45
|
|
-// Text acctID = new Text(acctFields[0]);
|
46
|
|
-// Text name = new Text(acctFields[1]);
|
47
|
|
-// Text email = new Text(acctFields[2]);
|
48
|
|
-// Text balance = new Text(acctFields[3]);
|
49
|
44
|
|
50
|
|
-// grid.setAlignment(Pos.CENTER_LEFT);
|
51
|
|
-// grid.setHgap(10);
|
52
|
|
-// grid.setVgap(10);
|
53
|
|
-// Text gridTitle = new Text("Your account details");
|
54
|
|
-// gridTitle.setFont(Font.font("Times New Roman", FontWeight.SEMI_BOLD, 14));
|
55
|
|
-// grid.add(gridTitle, 0, 0, 2, 1);
|
56
|
|
-
|
57
|
|
-// grid.add(acctID,1,1);
|
58
|
|
-// grid.add(name,1,2);
|
59
|
|
-// grid.add(email,1,3);
|
60
|
|
-// grid.add(balance,1,4);
|
61
|
|
-
|
62
|
|
-// grid.setPadding(new Insets(100,300,250,50));
|
63
|
|
-
|
64
|
|
- flowpane.getChildren().add(btnSubmit);
|
65
|
|
-
|
66
|
|
-
|
67
|
|
- vbox.getChildren().addAll(field, amountField, flowpane, areaInfo); //grid);
|
68
|
|
- return vbox;
|
69
|
|
- }
|
70
|
|
-
|
71
|
|
- private Parent createContent2(){
|
72
|
|
- FlowPane flowpane = new FlowPane();
|
73
|
|
- Text areaInfo = new Text();
|
74
|
|
- areaInfo.setVisible(true);
|
75
|
|
- amountField.setPromptText("Enter amounts");
|
76
|
|
- areaInfo.setText(cashMachine.toString());
|
77
|
|
-
|
78
|
|
- VBox vbox = new VBox(10);
|
79
|
|
- vbox.setPrefSize(600, 600);
|
|
45
|
+ MenuBar menuBar = new MenuBar();
|
80
|
46
|
|
81
|
47
|
Button btnDeposit = new Button("Deposit");
|
82
|
48
|
btnDeposit.setOnAction(e -> {
|
83
|
|
- double amount = Integer.parseInt(amountField.getText());
|
|
49
|
+ int amount = Integer.parseInt(field.getText());
|
84
|
50
|
cashMachine.deposit(amount);
|
85
|
51
|
|
86
|
|
- areaInfo.setText(cashMachine.toString());
|
87
|
|
-
|
|
52
|
+ account.setText(cashMachine.accountIdToString());
|
|
53
|
+ name.setText(cashMachine.nameToString());
|
|
54
|
+ email.setText(cashMachine.emailToString());
|
|
55
|
+ balance.setText(cashMachine.balanceToString());
|
88
|
56
|
});
|
89
|
57
|
|
90
|
|
-
|
91
|
58
|
Button btnWithdraw = new Button("Withdraw");
|
92
|
59
|
btnWithdraw.setOnAction(e -> {
|
93
|
|
- double amount = Integer.parseInt(amountField.getText());
|
|
60
|
+ int amount = Integer.parseInt(field.getText());
|
94
|
61
|
cashMachine.withdraw(amount);
|
95
|
62
|
|
96
|
|
- areaInfo.setText(cashMachine.toString());
|
|
63
|
+ account.setText(cashMachine.accountIdToString());
|
|
64
|
+ name.setText(cashMachine.nameToString());
|
|
65
|
+ email.setText(cashMachine.emailToString());
|
|
66
|
+ balance.setText(cashMachine.balanceToString());
|
97
|
67
|
});
|
98
|
68
|
|
99
|
69
|
Button btnExit = new Button("Exit");
|
100
|
70
|
btnExit.setOnAction(e -> {
|
101
|
71
|
cashMachine.exit();
|
|
72
|
+ account.setText(cashMachine.accountIdToString());
|
|
73
|
+ name.setText(cashMachine.nameToString());
|
|
74
|
+ email.setText(cashMachine.emailToString());
|
|
75
|
+ balance.setText(cashMachine.balanceToString());
|
|
76
|
+ });
|
|
77
|
+
|
|
78
|
+ Button btnSubmit = new Button("Login");
|
|
79
|
+ btnSubmit.setOnAction(e -> {
|
|
80
|
+ int id = Integer.parseInt(field.getText());
|
|
81
|
+ cashMachine.login(id);
|
|
82
|
+ account.setText(cashMachine.accountIdToString());
|
|
83
|
+ name.setText(cashMachine.nameToString());
|
|
84
|
+ email.setText(cashMachine.emailToString());
|
|
85
|
+ balance.setText(cashMachine.balanceToString());
|
|
86
|
+ btnDeposit.setVisible(true);
|
|
87
|
+ btnWithdraw.setVisible(true);
|
|
88
|
+ btnExit.setVisible(true);
|
|
89
|
+ menuBar.setVisible(true);
|
|
90
|
+
|
102
|
91
|
|
103
|
|
- areaInfo.setText(cashMachine.toString());
|
104
|
92
|
});
|
105
|
93
|
|
|
94
|
+ btnDeposit.setVisible(false);
|
|
95
|
+ btnWithdraw.setVisible(false);
|
|
96
|
+ btnExit.setVisible(false);
|
|
97
|
+ menuBar.setVisible(false);
|
|
98
|
+
|
|
99
|
+ Menu accountMenu = new Menu("All Accounts");
|
|
100
|
+
|
|
101
|
+ flowpane.getChildren().add(btnSubmit);
|
106
|
102
|
flowpane.getChildren().add(btnDeposit);
|
107
|
103
|
flowpane.getChildren().add(btnWithdraw);
|
108
|
104
|
flowpane.getChildren().add(btnExit);
|
109
|
|
-
|
110
|
|
- vbox.getChildren().addAll(amountField, flowpane, areaInfo); //grid);
|
|
105
|
+ flowpane.getChildren().add(menuBar);
|
|
106
|
+ menuBar.getMenus().add(accountMenu);
|
|
107
|
+
|
|
108
|
+ ArrayList<String> accountList = cashMachine.listAccounts();
|
|
109
|
+ for(String acct : accountList){
|
|
110
|
+ MenuItem newItem = new MenuItem(acct);
|
|
111
|
+ newItem.setOnAction(e -> {
|
|
112
|
+ field.clear();
|
|
113
|
+ field.setPromptText("Enter Id and click \"Login\"");
|
|
114
|
+ });
|
|
115
|
+
|
|
116
|
+ accountMenu.getItems().add(newItem);
|
|
117
|
+
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ gridPane.setPadding(new Insets(25,25,25,25));
|
|
121
|
+ gridPane.add(account,0,1);
|
|
122
|
+ gridPane.add(name,0,2);
|
|
123
|
+ gridPane.add(email,0,3);
|
|
124
|
+ gridPane.add(balance,0,4);
|
|
125
|
+ vbox.getChildren().addAll(field, flowpane, gridPane);
|
111
|
126
|
return vbox;
|
112
|
127
|
}
|
|
128
|
+
|
113
|
129
|
@Override
|
114
|
130
|
public void start(Stage stage) throws Exception {
|
115
|
|
- stage.setTitle("Cash Machine");
|
116
|
131
|
stage.setScene(new Scene(createContent()));
|
117
|
132
|
stage.show();
|
118
|
133
|
}
|