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();
      }
    }
  }
  private void refreshDialog() {
    String nr = currentAccountNumber();
    accountcombo.removeAllItems();
    if (bank != null) {
      try {
        Set<String> s = bank.getAccountNumbers();
        ArrayList<String> accnumbers = new ArrayList<String>(s);
        Collections.sort(accnumbers);
        ignoreItemChanges = true;
        for (String item : accnumbers) {
          accountcombo.addItem(item);
          if (item.equals(nr)) accountcombo.setSelectedItem(item);
        }
        ignoreItemChanges = false;

        // clean up local accounts map
        for (String key : s) {
          if (!accounts.containsKey(key)) {
            accounts.put(key, bank.getAccount(key));
          }
        }
        Iterator<String> it = accounts.keySet().iterator();
        while (it.hasNext()) {
          if (!s.contains(it.next())) it.remove();
        }

        int size = s.size();
        btn_deposit.setEnabled(size > 0);
        btn_withdraw.setEnabled(size > 0);
        btn_transfer.setEnabled(size > 1);
        item_close.setEnabled(size > 0);

        for (BankTest t : tests) {
          JMenuItem m = testMenuItems.get(t);
          m.setEnabled(t.isEnabled(size));
        }

        updateCustomerInfo();
      } catch (Exception e) {
        error(e);
      }
    }
  }