intellij version of CashMachineBlueJ

CashMachineApp.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package rocks.zipcode.atm;
  2. import javafx.event.ActionEvent;
  3. import javafx.event.EventHandler;
  4. import javafx.geometry.Insets;
  5. import javafx.geometry.Pos;
  6. import javafx.scene.control.Label;
  7. import javafx.scene.layout.GridPane;
  8. import javafx.scene.layout.StackPane;
  9. import rocks.zipcode.atm.bank.Bank;
  10. import javafx.application.Application;
  11. import javafx.scene.Parent;
  12. import javafx.scene.Scene;
  13. import javafx.scene.control.Button;
  14. import javafx.scene.control.TextArea;
  15. import javafx.scene.control.TextField;
  16. import javafx.scene.layout.VBox;
  17. import javafx.stage.Stage;
  18. import javafx.scene.layout.FlowPane;
  19. /**
  20. * @author ZipCodeWilmington
  21. */
  22. public class CashMachineApp extends Application {
  23. private Stage window;
  24. Scene mainContent, loginScene;
  25. private TextField field = new TextField();
  26. private CashMachine cashMachine = new CashMachine(new Bank());
  27. @Override
  28. public void start(Stage stage) throws Exception {
  29. window = stage;
  30. window.setTitle("Zip Cloud Bank");
  31. //Log In Layout
  32. Label loginLabel = new Label("Welcome to Zip Cloud Bank!\nPlease log in.");
  33. Button btnLogIn = new Button("Log In");
  34. btnLogIn.setStyle("-fx-font-size: 15pt");
  35. btnLogIn.setOnAction(e -> {
  36. mainContent = new Scene(mainContent());
  37. window.setScene(mainContent);
  38. });
  39. GridPane loginLayout = new GridPane();
  40. loginLayout.setHgap(12);
  41. loginLayout.setVgap(12);
  42. loginLayout.setAlignment(Pos.CENTER);
  43. loginLayout.getChildren().addAll(loginLabel, field, btnLogIn);
  44. loginScene = new Scene(loginLayout,600, 600);
  45. window.setScene(loginScene);
  46. window.show();
  47. }
  48. private Parent mainContent() {
  49. VBox vbox = new VBox(10);
  50. vbox.setPrefSize(600, 600);
  51. TextArea areaInfo = new TextArea();
  52. Button btnSubmit = new Button("Set Account ID");
  53. btnSubmit.setOnAction(e -> {
  54. int id = Integer.parseInt(field.getText());
  55. cashMachine.login(id);
  56. areaInfo.setText(cashMachine.toString());
  57. });
  58. Button btnDeposit = new Button("Deposit");
  59. btnDeposit.setOnAction(e -> {
  60. int amount = Integer.parseInt(field.getText());
  61. cashMachine.deposit(amount);
  62. areaInfo.setText(cashMachine.toString());
  63. });
  64. Button btnWithdraw = new Button("Withdraw");
  65. btnWithdraw.setOnAction(e -> {
  66. int amount = Integer.parseInt(field.getText());
  67. cashMachine.withdraw(amount);
  68. areaInfo.setText(cashMachine.toString());
  69. });
  70. Button btnExit = new Button("Log Out");
  71. btnExit.setOnAction(e -> {
  72. cashMachine.logOut();
  73. areaInfo.setText(cashMachine.toString());
  74. });
  75. FlowPane flowpane = new FlowPane();
  76. flowpane.getChildren().add(btnSubmit);
  77. flowpane.getChildren().add(btnDeposit);
  78. flowpane.getChildren().add(btnWithdraw);
  79. flowpane.getChildren().add(btnExit);
  80. vbox.getChildren().addAll(field, flowpane, areaInfo);
  81. return vbox;
  82. }
  83. public static void main(String[] args) {
  84. launch(args);
  85. }
  86. }