intellij version of CashMachineBlueJ

CashMachineApp.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package rocks.zipcode.atm;
  2. import rocks.zipcode.atm.bank.Bank;
  3. import javafx.application.Application;
  4. import javafx.scene.Parent;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.TextArea;
  8. import javafx.scene.control.TextField;
  9. import javafx.scene.layout.VBox;
  10. import javafx.stage.Stage;
  11. import javafx.scene.layout.FlowPane;
  12. /**
  13. * @author ZipCodeWilmington
  14. */
  15. public class CashMachineApp extends Application {
  16. private TextField field = new TextField();
  17. private CashMachine cashMachine = new CashMachine(new Bank());
  18. private Parent createContent() {
  19. VBox vbox = new VBox(10);
  20. vbox.setPrefSize(600, 600);
  21. TextArea areaInfo = new TextArea();
  22. Button btnSubmit = new Button("Set Account ID");
  23. btnSubmit.setOnAction(e -> {
  24. int id = Integer.parseInt(field.getText());
  25. cashMachine.login(id);
  26. areaInfo.setText(cashMachine.toString());
  27. });
  28. Button btnDeposit = new Button("Deposit");
  29. btnDeposit.setOnAction(e -> {
  30. int amount = Integer.parseInt(field.getText());
  31. cashMachine.deposit(amount);
  32. areaInfo.setText(cashMachine.toString());
  33. });
  34. Button btnWithdraw = new Button("Withdraw");
  35. btnWithdraw.setOnAction(e -> {
  36. int amount = Integer.parseInt(field.getText());
  37. cashMachine.withdraw(amount);
  38. areaInfo.setText(cashMachine.toString());
  39. });
  40. Button btnExit = new Button("Exit");
  41. btnExit.setOnAction(e -> {
  42. cashMachine.exit();
  43. areaInfo.setText(cashMachine.toString());
  44. });
  45. FlowPane flowpane = new FlowPane();
  46. flowpane.getChildren().add(btnSubmit);
  47. flowpane.getChildren().add(btnDeposit);
  48. flowpane.getChildren().add(btnWithdraw);
  49. flowpane.getChildren().add(btnExit);
  50. vbox.getChildren().addAll(field, flowpane, areaInfo);
  51. return vbox;
  52. }
  53. @Override
  54. public void start(Stage stage) throws Exception {
  55. stage.setScene(new Scene(createContent()));
  56. stage.show();
  57. }
  58. public static void main(String[] args) {
  59. launch(args);
  60. }
  61. }