private void onCreateNewAuctionClicked() {
    try {
      int startingPrice;
      String description = txtDescription.getText();

      if (txtStartingPrice.getText().equals("")) {
        startingPrice = 0;
      } else {
        startingPrice = Integer.parseInt(txtStartingPrice.getText());
      }

      // Get a reference to an inactive auction from the auction manager.
      String auctionRef = auctionFactoryImpl.getInactiveAuction();

      // resolve the Object Reference in Naming
      Auction auctionImpl = AuctionHelper.narrow(ncRef.resolve_str(auctionRef));

      // Put an item up for sale
      auctionImpl.offerItem(userName, description, startingPrice);

      // Update the auction lists
      updateAuctionLists(false);

      appletDisplay("Started new auction");

    } catch (NumberFormatException e1) {
      appletDisplay("Invalid starting price");
    } catch (AuctionFailure e2) {
      appletDisplay(e2.description);
    } catch (Exception e3) {
      appletDisplay("Unable to create a new auction");
      System.out.println("ERROR : " + e3);
      e3.printStackTrace(System.out);
    }
  }
  private void onLoginClicked() {
    try {
      if (usernameField.getText().equals("") || passwordField.getText().equals("")) {
        throw new AuctionFailure(ErrorType.GENERIC_ERROR, "Invalid login info");
      }
      userName = usernameField.getText();
      auctionFactoryImpl.authenticate(userName, passwordField.getText());

      // Authentication was successful
      appletDisplay(usernameField.getText() + " logged in");

      // Enable functionality
      btnRefresh.setEnabled(true);
      sellList.setEnabled(true);
      bidList.setEnabled(true);
      btnCreateNewAuction.setEnabled(true);
      txtDescription.setEnabled(true);
      txtStartingPrice.setEnabled(true);
      btnSellItem.setEnabled(true);
      btnBid.setEnabled(true);
      txtBidPrice.setEnabled(true);
      loggedIn = true;

      // Update the auction lists
      updateAuctionLists(false);

    } catch (AuctionFailure e) {
      appletDisplay(e.description);

      // Disable functionality
      btnRefresh.setEnabled(false);
      sellList.setEnabled(false);
      bidList.setEnabled(false);
      btnCreateNewAuction.setEnabled(false);
      txtDescription.setEnabled(false);
      txtStartingPrice.setEnabled(false);
      btnSellItem.setEnabled(false);
      btnBid.setEnabled(false);
      txtBidPrice.setEnabled(false);
      loggedIn = false;
    } catch (Exception e1) {
      appletDisplay("Unable to log in");
      System.out.println("ERROR : " + e1);
      e1.printStackTrace(System.out);
    }
  }
  public synchronized void updateAuctionLists(boolean isBackgroundThread) {
    AuctionsHolder sellerAuctions = new AuctionsHolder();
    AuctionsHolder bidderAuctions = new AuctionsHolder();
    IntHolder numSellerAuctions = new IntHolder();
    IntHolder numBidderAuctions = new IntHolder();

    try {
      auctionFactoryImpl.getActiveAuctions(
          userName, sellerAuctions, numSellerAuctions, bidderAuctions, numBidderAuctions);

      int sellIndex = sellList.getSelectedIndex();
      int bidIndex = bidList.getSelectedIndex();

      // Clear the lists
      sellListModel.clear();
      bidListModel.clear();

      // Re-populate the lists
      for (int idx = 0; idx < numSellerAuctions.value; idx++) {
        sellListModel.addElement(sellerAuctions.value[idx]);
      }
      for (int idx = 0; idx < numBidderAuctions.value; idx++) {
        bidListModel.addElement(bidderAuctions.value[idx]);
      }

      // Set the selected list index back to what it was before if possible
      if (sellIndex < sellListModel.getSize()) {
        sellList.setSelectedIndex(sellIndex);
      }
      if (bidIndex < bidListModel.getSize()) {
        bidList.setSelectedIndex(bidIndex);
      }

      if (!isBackgroundThread) {
        appletDisplay("Updated auction lists");
      }

    } catch (AuctionFailure e) {
      appletDisplay(e.description);
    } catch (Exception e1) {
      appletDisplay("Unable to update auction lists");
      System.out.println("ERROR : " + e1);
      e1.printStackTrace(System.out);
    }
  }