Пример #1
0
 public void withdraw() {
   String number = currentAccountNumber();
   if (number != null) {
     String s =
         JOptionPane.showInputDialog(
             this, "Enter amount to draw:", "Draw Money", JOptionPane.QUESTION_MESSAGE);
     if (s != null) {
       try {
         double amount = Double.parseDouble(s);
         Account a = accounts.get(number);
         a.withdraw(amount);
         fld_balance.setText(currencyFormat(a.getBalance()));
       } catch (NumberFormatException e) {
         JOptionPane.showMessageDialog(this, "Illegal Value", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (IllegalArgumentException e) {
         JOptionPane.showMessageDialog(
             this, "Illegal Argument", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (InactiveException e) {
         JOptionPane.showMessageDialog(
             this, "Account is inactive", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (OverdrawException e) {
         JOptionPane.showMessageDialog(
             this, "Account must not be overdrawn", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (Exception e) {
         error(e);
       }
     }
   }
 }
Пример #2
0
  public void transfer() {
    String number = currentAccountNumber();
    if (number != null) {
      try {
        Set<String> s = new HashSet<String>(accounts.keySet());
        s.remove(number);

        TransferDialog trans = new TransferDialog(this, "Transfer Money", number, s);
        Point loc = getLocation();
        trans.setLocation(loc.x + 50, loc.y + 50);
        trans.setModal(true);
        trans.setVisible(true);

        if (!trans.canceled()) {
          if (number.equals(trans.getAccountNumber())) {
            JOptionPane.showMessageDialog(
                this, "Both Accounts are the same!", "Error", JOptionPane.ERROR_MESSAGE);
          } else {
            try {
              double amount = Double.parseDouble(trans.getBalance());
              Account from = accounts.get(number);
              Account to = accounts.get(trans.getAccountNumber());
              bank.transfer(from, to, amount);

              // after transfer adjust value of displayed account
              fld_balance.setText(currencyFormat(from.getBalance()));

              JOptionPane.showMessageDialog(
                  this, "Transfer successfull", "Information", JOptionPane.INFORMATION_MESSAGE);
            } catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(
                  this, "Illegal Balance", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (IllegalArgumentException e) {
              JOptionPane.showMessageDialog(
                  this, "Illegal Argument", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (InactiveException e) {
              JOptionPane.showMessageDialog(
                  this, "At least one account is inactive", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (OverdrawException e) {
              JOptionPane.showMessageDialog(
                  this, "Account must not be overdrawn", "Error", JOptionPane.ERROR_MESSAGE);
            }
          }
        }
      } catch (Exception e) {
        error(e);
      }
    }
  }
Пример #3
0
 private void updateCustomerInfo() {
   String nr = currentAccountNumber();
   try {
     if (nr != null) {
       Account a = accounts.get(nr);
       if (a != null) {
         fld_owner.setText(a.getOwner());
         fld_balance.setText(currencyFormat(a.getBalance()));
       } else {
         JOptionPane.showMessageDialog(
             this, "Account not found", "Error", JOptionPane.ERROR_MESSAGE);
         refreshDialog();
       }
     } else {
       fld_owner.setText("");
       fld_balance.setText("");
     }
   } catch (Exception e) {
     error(e);
   }
 }