Quellcode durchsuchen

Finished with balance history

NedRedmond vor 6 Jahren
Ursprung
Commit
6aa35945b0

+ 34
- 0
src/main/java/AccountController.java Datei anzeigen

@@ -1,12 +1,20 @@
1 1
 import com.jfoenix.controls.JFXButton;
2 2
 import com.jfoenix.controls.JFXTabPane;
3 3
 import com.jfoenix.controls.JFXTextArea;
4
+import javafx.collections.FXCollections;
5
+import javafx.collections.ObservableList;
4 6
 import javafx.event.Event;
5 7
 import javafx.fxml.FXML;
6 8
 import javafx.scene.control.Tab;
9
+import javafx.scene.control.TableColumn;
10
+import javafx.scene.control.TableView;
7 11
 import javafx.scene.control.TextField;
12
+import javafx.scene.control.cell.PropertyValueFactory;
8 13
 import rocks.zipcode.atm.CashMachine;
14
+import rocks.zipcode.atm.bank.Transaction;
9 15
 
16
+import java.util.Date;
17
+import java.util.Observable;
10 18
 import java.util.concurrent.TimeUnit;
11 19
 
12 20
 /**
@@ -35,6 +43,15 @@ public class AccountController {
35 43
                 amountField.setText(newValue.replaceAll("[^\\d]", ""));
36 44
             }
37 45
         });
46
+
47
+        table.setEditable(true);
48
+        typCol.setCellValueFactory(new PropertyValueFactory<Transaction, String>("credit"));
49
+        datCol.setCellValueFactory(new PropertyValueFactory<Transaction, Date>("date"));
50
+        amtCol.setCellValueFactory(new PropertyValueFactory<Transaction, Long>("amount"));
51
+        balCol.setCellValueFactory(new PropertyValueFactory<Transaction, Long>("balance"));
52
+        table.getColumns().addAll(typCol,datCol,amtCol,balCol);
53
+        table.setItems(data);
54
+
38 55
     }
39 56
 
40 57
     @FXML
@@ -58,6 +75,17 @@ public class AccountController {
58 75
     }
59 76
 
60 77
     @FXML
78
+    private TableView<Transaction> table;
79
+
80
+    private final ObservableList<Transaction> data =
81
+            FXCollections.observableArrayList();
82
+
83
+    @FXML TableColumn<Transaction, String> typCol;
84
+    @FXML TableColumn<Transaction, Date> datCol;
85
+    @FXML TableColumn<Transaction, Long> amtCol;
86
+    @FXML TableColumn<Transaction, Long> balCol;
87
+
88
+    @FXML
61 89
     void transactionTab(Event event) {
62 90
         if (amountField.isDisabled()) {
63 91
             amountField.setDisable(false);
@@ -72,15 +100,21 @@ public class AccountController {
72 100
     void submit(Event event) {
73 101
         int amount = Integer.parseInt(amountField.getText());
74 102
 
103
+        String type = "";
104
+
75 105
         switch (tabPane.getSelectionModel().getSelectedItem().getText())
76 106
         {
77 107
             case "Withdraw": CashMachine.INSTANCE.withdraw(amount);
108
+                type = "Debit";
78 109
                 break;
79 110
             case "Deposit": CashMachine.INSTANCE.deposit(amount);
111
+                type = "Credit";
80 112
                 break;
81 113
             default: textArea.setText("Please select a tab.");
82 114
         }
83 115
         textArea.setText(CashMachine.INSTANCE.toString());
116
+
117
+        data.add(0, new Transaction(type, Integer.parseInt(amountField.getText()), CashMachine.INSTANCE.getBalance()));
84 118
     }
85 119
 
86 120
     @FXML

+ 14
- 5
src/main/java/LoginController.java Datei anzeigen

@@ -9,11 +9,20 @@ import rocks.zipcode.atm.CashMachine;
9 9
  */
10 10
 public class LoginController {
11 11
 
12
-    /**
13
-     * Event handler fired when the user requests a new vista.
14
-     *
15
-     * @param event the event that triggered the handler.
16
-     */
12
+//    /**
13
+//     * Event handler fired when the user requests a new vista.
14
+//     *
15
+//     * @param event the event that triggered the handler.
16
+//     */
17
+
18
+    @FXML
19
+    protected void initialize() {
20
+        pinEntry.textProperty().addListener((observable, oldValue, newValue) -> {
21
+            if (!newValue.matches("\\d*")) {
22
+                pinEntry.setText(newValue.replaceAll("[^\\d]", ""));
23
+            }
24
+        });
25
+    }
17 26
 
18 27
     @FXML
19 28
     private JFXTextField emailEntry;

+ 4
- 0
src/main/java/rocks/zipcode/atm/CashMachine.java Datei anzeigen

@@ -99,4 +99,8 @@ public class CashMachine {
99 99
             System.out.println("Error: " + e.getMessage());
100 100
         }
101 101
     }
102
+
103
+    public int getBalance() {
104
+        return accountData.getBalance();
105
+    }
102 106
 }

+ 53
- 0
src/main/java/rocks/zipcode/atm/bank/Transaction.java Datei anzeigen

@@ -0,0 +1,53 @@
1
+package rocks.zipcode.atm.bank;
2
+
3
+import java.text.SimpleDateFormat;
4
+import java.util.Date;
5
+
6
+public class Transaction {
7
+    private String date;
8
+    private String credit;
9
+    private int amount;
10
+    private int balance;
11
+
12
+    public String getCurrentTime() {
13
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
14
+        Date now = new Date();
15
+        String strDate = simpleDateFormat.format(now);
16
+        return strDate;
17
+    }
18
+
19
+    public Transaction(String credit, int amount, int balance) {
20
+        this.date = getCurrentTime();
21
+        this.credit = credit;
22
+        this.amount = amount;
23
+        this.balance = balance;
24
+    }
25
+
26
+    public String getDate() {
27
+        return date;
28
+    }
29
+
30
+    public String getCredit() {
31
+        return credit;
32
+    }
33
+
34
+    public void setCredit(String credit) {
35
+        this.credit = credit;
36
+    }
37
+
38
+    public int getAmount() {
39
+        return amount;
40
+    }
41
+
42
+    public void setAmount(int amount) {
43
+        this.amount = amount;
44
+    }
45
+
46
+    public int getBalance() {
47
+        return balance;
48
+    }
49
+
50
+    public void setBalance(int balance) {
51
+        this.balance = balance;
52
+    }
53
+}

+ 62
- 55
src/main/resources/accountview.fxml Datei anzeigen

@@ -19,59 +19,66 @@
19 19
 <!--</StackPane>-->
20 20
 
21 21
 <VBox fx:id="vista2" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="AccountController">
22
-  <children>
23
-    <JFXTabPane fx:id="tabPane" prefHeight="60.0" prefWidth="466.0">
24
-      <tabs>
25
-            <Tab fx:id="tabInfo" onSelectionChanged="#displayInfo" text="Account Info">
26
-              <content>
27
-                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
28
-              </content>
29
-            </Tab>
30
-        <Tab fx:id="tabWithdraw" onSelectionChanged="#transactionTab" text="Withdraw">
31
-          <content>
32
-            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
33
-          </content>
34
-        </Tab>
35
-        <Tab fx:id="tabDeposit" onSelectionChanged="#transactionTab" text="Deposit">
36
-          <content>
37
-            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
38
-          </content>
39
-        </Tab>
40
-        <Tab fx:id="tabLogout" onSelectionChanged="#logOut" text="Log Out">
41
-          <content>
42
-            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
43
-          </content>
44
-        </Tab>
45
-      </tabs>
46
-    </JFXTabPane>
47
-      <FlowPane fx:id="amountEntryPane" alignment="CENTER_LEFT" columnHalignment="CENTER" hgap="15.0" prefHeight="30.0" prefWidth="466.0" style="-fx-background-color: white;">
48
-         <children>
49
-            <TextField fx:id="amountField" disable="true" maxWidth="1.7976931348623157E308" prefHeight="36.0" prefWidth="121.0" text="Amount">
50
-               <font>
51
-                  <Font name="Futura Medium" size="18.0" />
52
-               </font>
53
-            </TextField>
54
-            <JFXButton fx:id="amountSubmit" disable="true" onAction="#submit" maxWidth="1.7976931348623157E308" ripplerFill="CORAL" text="Submit" style="-fx-background-color: coral;" textFill="WHITE">
55
-               <font>
56
-                  <Font name="Futura Bold" size="18.0" />
57
-               </font>
58
-            </JFXButton>
59
-         </children>
60
-         <padding>
61
-            <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
62
-         </padding>
63
-      </FlowPane>
64
-    <JFXTextArea fx:id="textArea" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="180.0" prefWidth="450.0" text="TESTTESTESTTESTTESTTESTTESTTESTTESTTESTTESTTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST">
65
-         <font>
66
-            <Font name="Futura Medium" size="14.0" />
67
-         </font>
68
-         <opaqueInsets>
69
-            <Insets />
70
-         </opaqueInsets>
71
-         <VBox.margin>
72
-            <Insets left="8.0" right="8.0" />
73
-         </VBox.margin>
74
-      </JFXTextArea>
75
-    <JFXTreeTableView fx:id="transactionsView" prefHeight="120.0" prefWidth="466.0" />
76
-  </children>
22
+    <children>
23
+        <JFXTabPane fx:id="tabPane" minHeight="50.0" prefHeight="40.0" prefWidth="466.0">
24
+            <tabs>
25
+                <Tab fx:id="tabInfo" onSelectionChanged="#displayInfo" text="Account Info">
26
+                    <content>
27
+                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
28
+                    </content>
29
+                </Tab>
30
+                <Tab fx:id="tabWithdraw" onSelectionChanged="#transactionTab" text="Withdraw">
31
+                    <content>
32
+                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
33
+                    </content>
34
+                </Tab>
35
+                <Tab fx:id="tabDeposit" onSelectionChanged="#transactionTab" text="Deposit">
36
+                    <content>
37
+                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
38
+                    </content>
39
+                </Tab>
40
+                <Tab fx:id="tabLogout" onSelectionChanged="#logOut" text="Log Out">
41
+                    <content>
42
+                        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
43
+                    </content>
44
+                </Tab>
45
+            </tabs>
46
+        </JFXTabPane>
47
+        <FlowPane fx:id="amountEntryPane" alignment="CENTER_LEFT" columnHalignment="CENTER" hgap="15.0" prefHeight="30.0" prefWidth="466.0" style="-fx-background-color: transparent;">
48
+            <children>
49
+                <TextField fx:id="amountField" disable="true" maxWidth="1.7976931348623157E308" prefHeight="36.0" prefWidth="121.0" text="Amount">
50
+                    <font>
51
+                        <Font name="Futura Medium" size="18.0" />
52
+                    </font>
53
+                </TextField>
54
+                <JFXButton fx:id="amountSubmit" disable="true" maxWidth="1.7976931348623157E308" onAction="#submit" ripplerFill="CORAL" style="-fx-background-color: coral;" text="Submit" textFill="WHITE">
55
+                    <font>
56
+                        <Font name="Futura Bold" size="18.0" />
57
+                    </font>
58
+                </JFXButton>
59
+            </children>
60
+            <padding>
61
+                <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
62
+            </padding>
63
+        </FlowPane>
64
+        <JFXTextArea fx:id="textArea" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="110.0" prefWidth="450.0" text="TESTTESTESTTESTTESTTESTTESTTESTTESTTESTTESTTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST">
65
+            <font>
66
+                <Font name="Futura Medium" size="14.0" />
67
+            </font>
68
+            <opaqueInsets>
69
+                <Insets />
70
+            </opaqueInsets>
71
+            <VBox.margin>
72
+                <Insets left="8.0" right="8.0" />
73
+            </VBox.margin>
74
+        </JFXTextArea>
75
+        <TableView fx:id="table" maxHeight="1.7976931348623157E308" prefHeight="150.0" prefWidth="466.0">
76
+            <columns>
77
+                <TableColumn fx:id="typCol" prefWidth="50.0" text="Type" />
78
+                <TableColumn fx:id="datCol" prefWidth="125.0" text="Date" />
79
+                <TableColumn fx:id="amtCol" prefWidth="100.0" text="Amount" />
80
+                <TableColumn fx:id="balCol" prefWidth="150.0" text="Balance" />
81
+            </columns>
82
+        </TableView>
83
+    </children>
77 84
 </VBox>

+ 4
- 0
src/main/resources/zcb.css Datei anzeigen

@@ -4,4 +4,8 @@
4 4
 
5 5
 .jfx-tab-pane:top .depth-container .tab-header-area .headers-region .tab .jfx-rippler .tab-container .tab-label .text {
6 6
     -fx-font: 18 Futura;
7
+}
8
+
9
+.table-view .column-header {
10
+    -fx-background-color: lightgray;
7 11
 }