Ejemplo n.º 1
0
 public void deposit() {
   String number = currentAccountNumber();
   if (number != null) {
     String s =
         JOptionPane.showInputDialog(
             this, "Enter amount to deposit:", "Deposit Money", JOptionPane.QUESTION_MESSAGE);
     if (s != null) {
       try {
         double amount = Double.parseDouble(s);
         Account a = accounts.get(number);
         a.deposit(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 (Exception e) {
         error(e);
       }
     }
   }
 }
Ejemplo n.º 2
0
  public void addAccount() {
    AddAccountDialog addaccount = new AddAccountDialog(this, "Add Account");

    Point loc = getLocation();
    addaccount.setLocation(loc.x + 50, loc.y + 50);
    addaccount.setModal(true);
    addaccount.setVisible(true);

    if (!addaccount.canceled()) {
      String number = null;
      try {
        number = bank.createAccount(addaccount.getOwnerName());
      } catch (Exception e) {
        error(e);
      }

      if (number == null) {
        JOptionPane.showMessageDialog(
            this, "Account could not be created", "Error", JOptionPane.ERROR_MESSAGE);
      } else {
        try {
          Account acc = bank.getAccount(number);
          accounts.put(number, acc);

          String str = addaccount.getBalance().trim();
          double amount;
          if (str.equals("")) amount = 0;
          else amount = Double.parseDouble(str);
          acc.deposit(amount);
        } catch (NumberFormatException e) {
          JOptionPane.showMessageDialog(this, "Illegal Format", "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 (Exception e) {
          error(e);
        }
        ignoreItemChanges = true;
        accountcombo.addItem(number);
        accountcombo.setSelectedItem(number);
        ignoreItemChanges = false;
        refreshDialog();
      }
    }
  }