Bladeren bron

Before I go too far trying Scene Builder

NedRedmond 6 jaren geleden
bovenliggende
commit
dbf2c5f522

+ 10
- 0
pom.xml Bestand weergeven

18
         <!-- dependencies -->
18
         <!-- dependencies -->
19
     </properties>
19
     </properties>
20
 
20
 
21
+    <dependencies>
22
+        <!-- https://mvnrepository.com/artifact/com.jfoenix/jfoenix -->
23
+        <dependency>
24
+            <groupId>com.jfoenix</groupId>
25
+            <artifactId>jfoenix</artifactId>
26
+            <version>8.0.7</version>
27
+        </dependency>
28
+
29
+    </dependencies>
30
+
21
     <build>
31
     <build>
22
         <plugins>
32
         <plugins>
23
             <plugin>
33
             <plugin>

+ 14
- 3
src/main/java/rocks/zipcode/atm/CashMachine.java Bestand weergeven

22
         accountData = data;
22
         accountData = data;
23
     };
23
     };
24
 
24
 
25
+    private boolean errorExists = false;
26
+    private String errorMessage = null;
27
+
25
     public void login(int id) {
28
     public void login(int id) {
26
         tryCall(
29
         tryCall(
27
                 () -> bank.getAccountById(id),
30
                 () -> bank.getAccountById(id),
55
 
58
 
56
     @Override
59
     @Override
57
     public String toString() {
60
     public String toString() {
58
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
61
+        String displayString;
62
+        if (errorExists) {
63
+            displayString = errorMessage;
64
+        } else {
65
+            displayString = accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
66
+        }
67
+        return displayString;
59
     }
68
     }
60
 
69
 
61
     public <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
70
     public <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
62
         try {
71
         try {
63
             ActionResult<T> result = action.get();
72
             ActionResult<T> result = action.get();
64
             if (result.isSuccess()) {
73
             if (result.isSuccess()) {
74
+                errorExists = false;
65
                 T data = result.getData();
75
                 T data = result.getData();
66
                 postAction.accept(data);
76
                 postAction.accept(data);
67
             } else {
77
             } else {
68
-                String errorMessage = result.getErrorMessage();
78
+                errorExists = true;
79
+                errorMessage = result.getErrorMessage();
69
                 throw new RuntimeException(errorMessage);
80
                 throw new RuntimeException(errorMessage);
70
             }
81
             }
71
         } catch (Exception e) {
82
         } catch (Exception e) {
72
             System.out.println("Error: " + e.getMessage());
83
             System.out.println("Error: " + e.getMessage());
73
         }
84
         }
74
     }
85
     }
75
-}
86
+}

+ 38
- 8
src/main/java/rocks/zipcode/atm/CashMachineApp.java Bestand weergeven

1
 package rocks.zipcode.atm;
1
 package rocks.zipcode.atm;
2
 
2
 
3
+import javafx.event.ActionEvent;
4
+import javafx.event.EventHandler;
5
+import javafx.geometry.Insets;
6
+import javafx.geometry.Pos;
7
+import javafx.scene.control.Label;
8
+import javafx.scene.layout.GridPane;
9
+import javafx.scene.layout.StackPane;
3
 import rocks.zipcode.atm.bank.Bank;
10
 import rocks.zipcode.atm.bank.Bank;
4
 import javafx.application.Application;
11
 import javafx.application.Application;
5
 import javafx.scene.Parent;
12
 import javafx.scene.Parent;
15
  * @author ZipCodeWilmington
22
  * @author ZipCodeWilmington
16
  */
23
  */
17
 public class CashMachineApp extends Application {
24
 public class CashMachineApp extends Application {
18
-
25
+    private Stage window;
26
+    Scene mainContent, loginScene;
19
     private TextField field = new TextField();
27
     private TextField field = new TextField();
20
     private CashMachine cashMachine = new CashMachine(new Bank());
28
     private CashMachine cashMachine = new CashMachine(new Bank());
21
 
29
 
22
-    private Parent createContent() {
30
+    @Override
31
+    public void start(Stage stage) throws Exception {
32
+        window = stage;
33
+        window.setTitle("Zip Cloud Bank");
34
+
35
+
36
+        //Log In Layout
37
+        Label loginLabel = new Label("Welcome to Zip Cloud Bank!\nPlease log in.");
38
+        Button btnLogIn = new Button("Log In");
39
+        btnLogIn.setStyle("-fx-font-size: 15pt");
40
+        btnLogIn.setOnAction(e -> {
41
+            mainContent = new Scene(mainContent());
42
+            window.setScene(mainContent);
43
+        });
44
+
45
+        GridPane loginLayout = new GridPane();
46
+        loginLayout.setHgap(12);
47
+        loginLayout.setVgap(12);
48
+        loginLayout.setAlignment(Pos.CENTER);
49
+        loginLayout.getChildren().addAll(loginLabel, field, btnLogIn);
50
+
51
+        loginScene = new Scene(loginLayout,600, 600);
52
+        window.setScene(loginScene);
53
+
54
+
55
+        window.show();
56
+    }
57
+
58
+    private Parent mainContent() {
23
         VBox vbox = new VBox(10);
59
         VBox vbox = new VBox(10);
24
         vbox.setPrefSize(600, 600);
60
         vbox.setPrefSize(600, 600);
25
 
61
 
66
         return vbox;
102
         return vbox;
67
     }
103
     }
68
 
104
 
69
-    @Override
70
-    public void start(Stage stage) throws Exception {
71
-        stage.setScene(new Scene(createContent()));
72
-        stage.show();
73
-    }
74
-
75
     public static void main(String[] args) {
105
     public static void main(String[] args) {
76
         launch(args);
106
         launch(args);
77
     }
107
     }

+ 1
- 1
src/main/java/rocks/zipcode/atm/CashMachineSkin.fxml Bestand weergeven

8
 
8
 
9
 <AnchorPane xmlns="http://javafx.com/javafx"
9
 <AnchorPane xmlns="http://javafx.com/javafx"
10
             xmlns:fx="http://javafx.com/fxml"
10
             xmlns:fx="http://javafx.com/fxml"
11
-            fx:controller="$CONTROLLER_NAME$"
11
+            fx:controller="rocks.zipcode.atm.CashMachineApp"
12
             prefHeight="400.0" prefWidth="600.0">
12
             prefHeight="400.0" prefWidth="600.0">
13
 
13
 
14
 </AnchorPane>
14
 </AnchorPane>

+ 20
- 4
src/main/java/rocks/zipcode/atm/bank/Bank.java Bestand weergeven

14
 
14
 
15
     public Bank() {
15
     public Bank() {
16
         accounts.put(1000, new BasicAccount(new AccountData(
16
         accounts.put(1000, new BasicAccount(new AccountData(
17
-                1000, "Example 1", "example1@gmail.com", 500
17
+                1000, "Gulliver Grimwald", "ggrim@gmail.com", 500
18
+        )));
19
+
20
+        accounts.put(6666, new PremiumAccount(new AccountData(
21
+                6666, "B. L. Zebub", "mephis@hotmail.com", 666
18
         )));
22
         )));
19
 
23
 
20
         accounts.put(2000, new PremiumAccount(new AccountData(
24
         accounts.put(2000, new PremiumAccount(new AccountData(
21
-                2000, "Example 2", "example2@gmail.com", 200
25
+                2000, "Richard Ricardo", "rricardo@business.com", 20000
26
+        )));
27
+
28
+        accounts.put(0420, new BasicAccount(new AccountData(
29
+                0420, "Guy Dudero", "lmfao4eva@ymail.com", 69
30
+        )));
31
+
32
+        accounts.put(9999, new PremiumAccount(new AccountData(
33
+                9999, "Final Boss", "bosskey@gmail.com", 9999
34
+        )));
35
+
36
+        accounts.put(0001, new BasicAccount(new AccountData(
37
+                0001, "Bill Busker", "bboy@yandex.com", 0
22
         )));
38
         )));
23
     }
39
     }
24
 
40
 
41
 
57
 
42
     public ActionResult<AccountData> withdraw(AccountData accountData, int amount) {
58
     public ActionResult<AccountData> withdraw(AccountData accountData, int amount) {
43
         Account account = accounts.get(accountData.getId());
59
         Account account = accounts.get(accountData.getId());
44
-        boolean ok = account.withdraw(amount);
60
+        boolean canWithdraw = account.withdraw(amount);
45
 
61
 
46
-        if (ok) {
62
+        if (canWithdraw) {
47
             return ActionResult.success(account.getAccountData());
63
             return ActionResult.success(account.getAccountData());
48
         } else {
64
         } else {
49
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
65
             return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());