소스 검색

Drop down options for account number

Lauren Green 6 년 전
부모
커밋
14b1b34522

+ 14
- 0
src/main/java/rocks/zipcode/atm/CashMachine.java 파일 보기

@@ -1,8 +1,12 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
+import javafx.collections.FXCollections;
4
+import javafx.collections.ObservableList;
3 5
 import rocks.zipcode.atm.bank.AccountData;
4 6
 import rocks.zipcode.atm.bank.Bank;
5 7
 
8
+import java.util.ArrayList;
9
+import java.util.Observable;
6 10
 import java.util.function.Consumer;
7 11
 import java.util.function.Supplier;
8 12
 
@@ -15,13 +19,23 @@ public class CashMachine {
15 19
     private AccountData accountData = null;
16 20
 
17 21
     public CashMachine(Bank bank) {
22
+
18 23
         this.bank = bank;
24
+
25
+
19 26
     }
20 27
 
21 28
     private Consumer<AccountData> update = data -> {
22 29
         accountData = data;
23 30
     };
24 31
 
32
+    public ObservableList<Integer> getIdList() {
33
+
34
+        ObservableList<Integer> idList = FXCollections.observableArrayList(bank.getIdList());
35
+
36
+        return idList;
37
+    }
38
+
25 39
     public void login(int id) {
26 40
         tryCall(
27 41
                 () -> bank.getAccountById(id),

+ 23
- 12
src/main/java/rocks/zipcode/atm/CashMachineApp.java 파일 보기

@@ -1,27 +1,36 @@
1 1
 package rocks.zipcode.atm;
2 2
 
3
-import javafx.scene.control.Label;
3
+import javafx.scene.control.*;
4
+import javafx.scene.layout.HBox;
4 5
 import javafx.stage.StageStyle;
5 6
 import rocks.zipcode.atm.bank.Bank;
6 7
 import javafx.application.Application;
7 8
 import javafx.scene.Parent;
8 9
 import javafx.scene.Scene;
9
-import javafx.scene.control.Button;
10
-import javafx.scene.control.TextArea;
11
-import javafx.scene.control.TextField;
12 10
 import javafx.scene.layout.VBox;
13 11
 import javafx.stage.Stage;
14 12
 import javafx.scene.layout.FlowPane;
15 13
 
14
+import java.util.HashMap;
15
+
16 16
 /**
17 17
  * @author ZipCodeWilmington
18 18
  */
19 19
 public class CashMachineApp extends Application {
20 20
 
21
+
22
+/*
23
+    HashMap<String, String> estados = EstadosBrasil.getEstados();
24
+for(Entry<String, String> e : estados.entrySet()){
25
+        Object obj = comboEstado.addItem();
26
+        comboEstado.setItemCaption(e.getKey(), e.getValue());
27
+        comboEstado.setValue(obj);
28
+    }*/
29
+
21 30
     private TextField field = new TextField();
22 31
     private TextField field2 = new TextField();
23 32
     private CashMachine cashMachine = new CashMachine(new Bank());
24
-
33
+    private ComboBox accountNumbers = new ComboBox(cashMachine.getIdList());
25 34
 
26 35
     private Parent createContent() {
27 36
         VBox vbox = new VBox(10);
@@ -60,7 +69,7 @@ public class CashMachineApp extends Application {
60 69
             areaInfo.setText(cashMachine.toString());
61 70
         });
62 71
 
63
-        Button btnExit = new Button("LogOut");
72
+        Button btnExit = new Button("Log Out");
64 73
         btnExit.setOnAction(e -> {
65 74
             cashMachine.exit();
66 75
             field.clear();
@@ -72,7 +81,7 @@ public class CashMachineApp extends Application {
72 81
 
73 82
         Button btnSubmit = new Button("Enter");
74 83
         btnSubmit.setOnAction(e -> {
75
-            int id = Integer.parseInt(field.getText());
84
+            int id = Integer.parseInt(accountNumbers.getValue().toString());
76 85
             cashMachine.login(id);
77 86
 
78 87
             areaInfo.setText(cashMachine.toString());
@@ -96,7 +105,7 @@ public class CashMachineApp extends Application {
96 105
         field.setStyle("-fx-background-color: beige;");
97 106
         field2.setStyle("-fx-background-color: beige;");
98 107
         Label fieldLabel = new Label("Account Number:");
99
-        vbox.getChildren().addAll(fieldLabel, field, flowpane, fieldLabel2, field2, flowpane2, accountInfo2, areaInfo);
108
+        vbox.getChildren().addAll(fieldLabel, accountNumbers, flowpane, fieldLabel2, field2, flowpane2, accountInfo2, areaInfo);
100 109
 
101 110
 
102 111
 
@@ -106,15 +115,17 @@ public class CashMachineApp extends Application {
106 115
     }
107 116
 
108 117
     @Override
109
-    public void start(Stage stage) throws Exception {
110
-        stage.setTitle("ZipCloud Bank");
111
-        stage.setScene(new Scene(createContent()));
112
-        stage.show();
118
+    public void start(Stage primarystage) throws Exception {
119
+        primarystage.setTitle("ZipCloud Bank");
120
+        primarystage.setScene(new Scene(createContent()));
121
+        primarystage.show();
113 122
 
114 123
     }
115 124
 
116 125
     public static void main(String[] args) {
126
+
117 127
         launch(args);
128
+
118 129
     }
119 130
 
120 131
 

+ 16
- 1
src/main/java/rocks/zipcode/atm/bank/Bank.java 파일 보기

@@ -1,7 +1,10 @@
1 1
 package rocks.zipcode.atm.bank;
2 2
 
3
+import javafx.collections.FXCollections;
4
+import javafx.collections.ObservableList;
3 5
 import rocks.zipcode.atm.ActionResult;
4 6
 
7
+import java.util.ArrayList;
5 8
 import java.util.HashMap;
6 9
 import java.util.Map;
7 10
 
@@ -21,7 +24,7 @@ public class Bank {
21 24
         )));
22 25
 
23 26
         accounts.put(1010, new BasicAccount(new AccountData(
24
-                1000, "Dan Green", "dgreen@gmail.com", 100000
27
+                1010, "Dan Green", "dgreen@gmail.com", 100000
25 28
         )));
26 29
 
27 30
         accounts.put(2000, new PremiumAccount(new AccountData(
@@ -44,6 +47,18 @@ public class Bank {
44 47
     }
45 48
 
46 49
 */
50
+
51
+    public ObservableList<Integer> getIdList() {
52
+
53
+        ObservableList<Integer> idList = FXCollections.observableArrayList();
54
+
55
+        for (Integer key: accounts.keySet()) {
56
+
57
+            idList.add(key);
58
+        }
59
+            return idList;
60
+    }
61
+
47 62
     public ActionResult<AccountData> getAccountById(int id) {
48 63
         Account account = accounts.get(id);
49 64