示例#1
0
  public void specialShoot(Coordinate explodeCoordinate) {

    if (alive && hasItem()) // no time limit
    {
      if (item.getType().equals("nuke")) {
        world.addProjectile(new Nuke(this, explodeCoordinate));
        item = null;
      } else if (item.getType().equals("starburst")) {
        world.addProjectile(new Starburst(this, explodeCoordinate, 2));
        item = null;
      } else if (item.getType().equals("laser")) {
        world.addProjectile(new Laser(this, explodeCoordinate));
        item = null;
      }
      /*else if(item.getType().equals("mine"))
      {
      	world.addProjectile(new StarburstProjectile(this,explodeCoordinate,2));
      	item=null;
      }*/
      else {

        System.out.println("unrecognised item shot: deleting...");
        item = null;
      }
    }

    // ,color));
    // System.out.println("tank shot");

  }
示例#2
0
  private void saveCurrent() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");

      for (String s : Main.getEmails()) {
        writer.println(s);
      }

      writer.println("Items:");

      for (Item s : Main.getItems()) {
        writer.println(s.getName() + "," + s.getWebsite());
      }

      results.setText("Current settings have been saved sucessfully.");
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
示例#3
0
 private void paintItems(Graphics2D g2d) {
   for (Item item : c.getAllStuff()) {
     if (item != null) {
       if (item.flicker()) {
         g2d.drawImage(
             item.getImage(), item.getPosition().getX(), item.getPosition().getY(), this);
       }
     }
   }
 }
 /**
  * Gets the count of all the inventory items matching with any of the provided ids.
  *
  * @param includeStacks <tt>true</tt> to count the stack sizes of each item; otherwise
  *     <tt>false</tt>
  * @param itemIds the item ids to include
  * @return the count
  */
 public static int getCount(boolean includeStacks, int... itemIds) {
   int count = 0;
   Item[] items = getItems(itemIds);
   for (Item item : items) {
     if (item == null) continue;
     int itemId = item.getId();
     if (itemId != -1) {
       count += includeStacks ? item.getStackSize() : 1;
     }
   }
   return count;
 }
 /**
  * Gets the selected inventory item's index.
  *
  * @return the index of the current selected inventory item; otherwise -1 if none is selected
  */
 public static int getSelectedItemIndex() {
   Item[] items = getItems();
   for (Item item : items) {
     if (item == null) {
       continue;
     }
     Component comp = item.getComponent();
     if (comp.getBorderThickness() == 2) {
       return comp.getIndex();
     }
   }
   return -1;
 }
 /**
  * Gets the count of all the inventory items excluding any of the provided ids.
  *
  * @param includeStacks <tt>true</tt> to count the stack sizes of each item; otherwise
  *     <tt>false</tt>
  * @param ids the ids to exclude
  * @return the count
  */
 public static int getCountExcept(boolean includeStacks, int... ids) {
   int count = 0;
   Item[] items = getItems();
   outer:
   for (Item item : items) {
     if (item == null) continue;
     int itemId = item.getId();
     for (int id : ids) {
       if (itemId == id) continue outer;
     }
     count += includeStacks ? item.getStackSize() : 1;
   }
   return count;
 }
示例#7
0
  public void setTeam(Team team) {
    this.team = team;
    if (hasItem()) item.reset();
    resetLocation();

    // if (team!=null)
    // color=team.getColor();

  }
 /**
  * Uses an item on a game object.
  *
  * @param item the item to use
  * @param target the game object to be used on by the item
  * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game
  *     object; otherwise <tt>false</tt>
  */
 public static boolean useItem(Item item, GameObject target) {
   if (item != null && target != null) {
     for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) {
       if (!isItemSelected()) {
         if (item.interact("Use")) {
           for (int j = 0; j < 10 && !isItemSelected(); j++) {
             Task.sleep(100, 200);
           }
         } else {
           return false;
         }
       }
       // just make sure in case something bad happened
       if (isItemSelected()) {
         final String itemName = item.getName();
         final ObjectDefinition targetDef = target.getDef();
         final Model targetModel = target.getModel();
         if (targetDef != null && itemName != null && targetModel != null) {
           final String targetName = targetDef.getName();
           Mouse.move(targetModel.getNextPoint());
           final String action =
               "Use "
                   + itemName.replace("<col=ff9040>", "")
                   + " -> "
                   + targetName.replace("<col=ff9040>", "");
           for (int j = 0, s = Random.nextInt(5, 8); j < s; j++) {
             if (Menu.contains(action) && Menu.click(action)) {
               return true;
             } else {
               Mouse.move(targetModel.getNextPoint());
             }
           }
         }
         // kay, since that failed, let's try just use
         if (target.interact("Use")) {
           return true;
         }
       }
     }
   }
   return false;
 }
示例#9
0
  private void checkContainedItem(ResourceEntry entry, StructEntry container) {
    List<StructEntry> cont_list = ((AbstractStruct) container).getList();
    for (int i = 0; i < cont_list.size(); i++)
      if (cont_list.get(i) instanceof Item) {
        Item item = (Item) cont_list.get(i);

        ResourceRef itemRes = (ResourceRef) item.getAttribute("Item");
        if (!ResourceFactory.getInstance().resourceExists(itemRes.getResourceName())) {
          errorTable.addTableItem(
              new AreaTableLine(
                  entry,
                  container,
                  "Non existent item in container: " + itemRes.getResourceName()));
        }

        StructEntry wear = item.getAttribute("Wear");
        if (((DecNumber) wear).getValue() != 0) {
          errorTable.addTableItem(
              new AreaTableLine(entry, container, "Wear is: " + ((DecNumber) wear).getValue()));
        }

        for (int j = 1; j < 8 * ((Flag) item.getAttribute("Flags")).getSize(); j++)
          if (((Flag) item.getAttribute("Flags")).isFlagSet(j)) {
            errorTable.addTableItem(
                new AreaTableLine(
                    entry, container, "Item flag is: " + item.getAttribute("Flags").toString()));
            break;
          }
      }
  }
示例#10
0
  public void buyItemFromUser(User buyer, User seller, Item currentItem)
        // PRE:  buyer, seller, currentItem must be initialized
        // POST: Purchases item from the store and has stores it into inventory.
      {

    int buyer_balance; // The new balance of the buyer
    int seller_balance; // The new balance of the seller
    String str; // First query
    String str2; // Second query
    String str3; // Third query

    buyer_balance = buyer.getBalance() - currentItem.getPrice();
    seller_balance = seller.getBalance() + currentItem.getPrice();

    if (buyer_balance > 0) // If the buyer wont go negative
    {
      str =
          String.format(
              "Update users set balance = (%d) where user_name = '%s'",
              buyer_balance, buyer.getUserName());

      str2 =
          String.format(
              "Update users set balance = (%d) where user_name = '%s'",
              seller_balance, seller.getUserName());

      str3 =
          String.format(
              "Update items set owner_id = (%d) where item_name = '%s'",
              buyer.getUserId(), currentItem.getItemName());

      updateTables(str, str2, str3);

    } else {
      // Prompt the user with an error
      JOptionPane.showMessageDialog(
          null, "You will go bankrupt if you try buying that, try selling some items.");
    }
  }
示例#11
0
  public void checkInput() {
    // SwingUtilities.invokeLater(new Runnable() {
    // public void run() {
    String text = inputText.getText();
    if (!text.equals("")) {
      appendToPane(text + "\n\n", Color.blue);
      inputText.setText("");
      if (text.startsWith("use ")) {
        ArrayList<Item> inventory = player.getInventory();
        String key = text.substring(4);
        boolean found = false;
        for (Item i : inventory) {
          if (i.getName().equalsIgnoreCase(key)) {
            found = true;
            i.use();
            break;
          }
        }
        if (!found) {
          appendToPane("Item does not exist in your iventory.\n\n", Color.black);
        } else {

        }
      }
      if (text.startsWith("inventory")) {
        ArrayList<Item> inventory = player.getInventory();
        if (inventory.size() > 0) {
          for (Item i : inventory) {
            appendToPane(i.getName() + "\n", Color.darkGray);
          }
        } else appendToPane("Your iventory is empty.\n\n", Color.black);
        appendToPane("#", Color.blue);
      } else {
        userInput = text;
      }
    }
    // }
    // });
  }
示例#12
0
  private void displayInformation() {
    results.setText("-Cell Phones-\n");
    if (Main.getEmails().isEmpty()) {
      results.append("\nNo Numbers");
    } else {
      ArrayList<String> emails = Main.getEmails();
      int index = 0;

      for (String s : emails) {
        index++;
        results.append("\n(" + index + ")   " + s);
      }
    }

    results.append("\n\n-Current Items-");
    if (Main.getItems().isEmpty()) {
      results.append("\n\nNo Items");
    } else {
      ArrayList<Item> items = Main.getItems();
      int index = 0;

      for (Item i : items) {
        String s = i.getWebsite().substring(46, i.getWebsite().length());

        index++;

        for (int j = 0; j < s.length(); j++) {
          if (s.substring(j, j + 1).equals("&")) {
            s = s.substring(0, j);
          }
        }

        results.append("\n\n(" + index + ")\nName: \t" + i.getName() + "\nItem: \t" + s);
      }
      results.append("\n\n");
    }
  }
 /**
  * Drags an item to the specified inventory slot, which must be in the range of 0 and 27.
  *
  * @param item the inventory item
  * @param invSlot the inventory slot
  * @return <tt>true</tt> if dragged; otherwise <tt>false</tt>
  */
 public static boolean drag(Item item, int invSlot) {
   if (item != null) {
     if (invSlot >= 0 && invSlot <= 27) {
       Component slot = getComponent().getComponents()[invSlot];
       if (slot != null) {
         Rectangle slotRectangle = slot.getBoundingRect();
         Rectangle itemRectangle = item.getComponent().getContentRect();
         if (slotRectangle.contains(itemRectangle)) {
           return true;
         }
         Mouse.move((int) itemRectangle.getCenterX(), (int) itemRectangle.getCenterY(), 5, 5);
         Mouse.drag((int) slotRectangle.getCenterX(), (int) slotRectangle.getCenterY());
         return true;
       }
     }
   }
   return false;
 }
示例#14
0
  public void move(double multiplier) {
    shootTime++;
    if (!alive) {
      if (deathWait) {
        deathWaitCount++;
        if (deathWaitCount > 50) {
          deathWait = false;
          if (hasItem()) item.reset();
          resetLocation();
        }

      } else {
        ghostCount++;
        if (ghostCount >= 100) alive = true;
      }
    }

    if (!deathWait) {
      double x = Math.cos(angle.getValue()) * speed * speedToggle * multiplier;
      double y = Math.sin(angle.getValue()) * speed * speedToggle * multiplier;
      for (Solid s : world.getSolids()) {
        boolean[] bools = s.collides(this);
        if (bools[0]) {
          if ((y > 0 && bools[1]) || (y < 0 && bools[2])) y = 0;
          if ((x > 0 && bools[3]) || (x < 0 && bools[4])) x = 0;
        }
      }

      // super.move(speed*multiplier*speedToggle);
      location.addX(x);
      location.addY(y);

      if (rotateToggle != 0) {
        if (Math.abs(rotateToggle) < maxRotateSpeed)
          rotate(rotateToggle); // go exact remainder of angle
        else rotate(rotateToggle * multiplier * maxRotateSpeed);
      }
    }
  }
示例#15
0
  private void drawItem(Graphics g, int item, Item currentItem) {
    Font font; // The font to be used.
    int x1; // The first x coordinate of drawing area.
    int y1; // The first y coordinate of drawing area.
    int x2; // The second x coordinate of drawing area.
    int y2; // The second y coordinate of drawing area.
    int width; // Width of drawing area.
    int height; // Height of drawing area.

    int iconX; // x coordinate of the icon.
    int iconY; // y coordinate of the icon.
    int iconLength; // Length of the icon.

    int itemNameX; // The x coordinate of the item name.
    int itemNameLength; // The length of the item name.

    int itemPriceX; // The x coordinate of the item price.
    int itemPriceWidth; // The width of the item price.

    x1 = itemPositions[item][0].getScaledX();
    x2 = itemPositions[item][1].getScaledX();
    y1 = itemPositions[item][0].getScaledY();
    y2 = itemPositions[item][1].getScaledY();
    width = x2 - x1;
    height = y2 - y1;

    iconX = x1 + (int) (width * .01);
    iconY = y1 + (int) (height * .1);
    iconLength = (int) (height * .8);

    Drawing.drawImage(g, iconX, iconY, iconLength, iconLength, currentItem.getItemPath());

    itemNameX = iconX + (int) (iconLength * 1.5);
    itemNameLength = (int) (width * 0.6);

    font =
        Drawing.getFont(
            currentItem.getItemName(),
            itemNameLength,
            (int) (iconLength * 0.8),
            FONTNAME,
            FONTSTYLE);

    g.setFont(font);
    g.setColor(Color.WHITE);
    g.drawString(currentItem.getItemName(), itemNameX, iconY + (int) (iconLength * 0.9));

    itemPriceX = x1 + (int) (width * 0.8);
    itemPriceWidth = (int) (width * 0.15);

    font =
        Drawing.getFont(
            Integer.toString(currentItem.getPrice()),
            itemPriceWidth,
            iconLength,
            FONTNAME,
            FONTSTYLE);
    g.setFont(font);
    g.setColor(Color.WHITE);
    g.drawString(
        Integer.toString(currentItem.getPrice()), itemPriceX, iconY + (int) (iconLength * .9));

    return;
  }
 /**
  * Clicks on the selected inventory item.
  *
  * @param leftClick <tt>true</tt> to left-click otherwise; <tt>false</tt> to right-click
  * @return <tt>true</tt> if the inventory item was clicked on; otherwise <tt>false</tt>
  */
 public static boolean clickSelectedItem(boolean leftClick) {
   Item item = getSelectedItem();
   return item != null && item.click(leftClick);
 }
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jbSaveLayer) {
      try {
        FileOutputStream fout = new FileOutputStream(jtfCengMing.getText() + ".wyf");
        ObjectOutputStream oout = new ObjectOutputStream(fout);
        oout.writeObject(itemArray);
        oout.close();
        fout.close();
      } catch (Exception ea) {
        ea.printStackTrace();
      }
    } else if (e.getSource() == jbLoadLayer) {
      try {
        FileInputStream fin = new FileInputStream(jtfCengMing.getText() + ".wyf");
        ObjectInputStream oin = new ObjectInputStream(fin);
        itemArray = (Item[][]) oin.readObject();

        oin.close();
        fin.close();
        this.flush();
      } catch (Exception ea) {
        ea.printStackTrace();
      }
      lvp.repaint();
    } else if (e.getSource() == jbLoadAll) { // 全部铺上当前选中

      for (int row = 0; row < 40; row++) {
        for (int col = 0; col < 60; col++) {
          Item item = ((Item) (jl.getSelectedValue())).clone();
          itemArray[row][col] = item;
          if (item != null) {
            item.setPosition(col, row);
          }
        }
      }

      lvp.repaint();
    } else if (e.getSource() == jbCreate) { // 生成源代码

      try {
        FileOutputStream fout = null;
        DataOutputStream dout = null;
        fout = new FileOutputStream("maps.so");
        dout = new DataOutputStream(fout);
        int totalBlocks = 0;

        for (int i = 0; i < 40; i++) {
          for (int j = 0; j < 60; j++) {
            Item item = itemArray[i][j];
            if (item != null) {
              totalBlocks++;
            }
          }
        }
        System.out.println("totalBlocks=" + totalBlocks);

        // 写入不空块的数量
        dout.writeInt(totalBlocks);

        for (int i = 0; i < 40; i++) {
          for (int j = 0; j < 60; j++) {
            Item item = itemArray[i][j];
            if (item != null) {
              int w = item.w; // 元素的图片宽度
              int h = item.h; // 元素的图片高度
              int col = item.col; // 元素的地图列
              int row = item.row; // 元素的地图行
              int pCol = item.pCol; // 元素的占位列
              int pRow = item.pRow; // 元素的占位行
              String leiMing = item.leiMing; // 类名

              int[][] notIn = item.notIn; // 不可通过
              int[][] keYu = item.keYu; // 可遇矩阵

              // 计算图片下标
              int outBitmapInxex = 0;
              if (leiMing.equals("Grass")) {
                outBitmapInxex = 0;
              } else if (leiMing.equals("XiaoHua1")) {
                outBitmapInxex = 1;
              } else if (leiMing.equals("MuZhuang")) {
                outBitmapInxex = 2;
              } else if (leiMing.equals("XiaoHua2")) {
                outBitmapInxex = 3;
              } else if (leiMing.equals("Road")) {
                outBitmapInxex = 4;
              } else if (leiMing.equals("Jing")) {
                outBitmapInxex = 5;
              }

              dout.writeByte(outBitmapInxex); // 记录图片下标
              dout.writeByte(0); // 记录可遇标志 0-不可遇 底层都不可遇
              dout.writeByte(w); // 图片宽度
              dout.writeByte(h); // 图片高度
              dout.writeByte(col); // 总列数
              dout.writeByte(row); // 总行数
              dout.writeByte(pCol); // 占位列
              dout.writeByte(pRow); // 占位行

              int bktgCount = notIn.length; // 不可通过点的数量
              dout.writeByte(bktgCount); // 写入不可通过点的数量

              for (int k = 0; k < bktgCount; k++) {
                dout.writeByte(notIn[k][0]);
                dout.writeByte(notIn[k][1]);
              }
            }
          }
        }

        dout.close();
        fout.close();

      } catch (Exception ea) {
        ea.printStackTrace();
      }
    }
  }
 /**
  * Uses an inventory item on either another inventory item or a game object.
  *
  * @param item the inventory item to use
  * @param target the inventory item or the game object to be used on by the inventory item
  * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game
  *     object/other inventory item; otherwise <tt>false</tt>
  */
 private static boolean useItem(Item item, Object target) {
   if (isItemSelected()) {
     Item selectedItem = getSelectedItem();
     int selectedItemId = selectedItem.getId();
     if (item.getId() != selectedItemId) {
       if (!selectedItem.interact("Cancel")) {
         return false;
       }
     } else if (target instanceof Item) {
       Item t = (Item) target;
       if (selectedItemId != t.getId() && selectedItemId != item.getId()) {
         if (!selectedItem.interact("Cancel")) {
           return false;
         }
       }
     }
   }
   for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) {
     if (isItemSelected()) {
       boolean success = false;
       for (int j = 0, k = Random.nextInt(5, 8); j < k; j++) {
         try {
           Item t = (Item) target;
           if (t.interact("Use")) {
             success = true;
             break;
           }
           Task.sleep(150, 300);
         } catch (final ClassCastException e) {
           return false;
         }
       }
       return success;
     }
     item.interact("Use");
     Task.sleep(150, 300);
   }
   return false;
 }
示例#19
0
  @Override
  public void keyPressed(KeyEvent e) {
    int option; // The option the user selected.
    User buyer; // User object for buyer
    User seller; // User object for seller
    Item selected_item; // Item object for selected item

    if (help) // if in help mode
    {
      return;
    }

    switch (e.getKeyCode()) // handle event associated with key
    {
      case KeyEvent.VK_F1: // if f1 was pressed
        switchStore(0);
        break;

      case KeyEvent.VK_F2: // if f2 was pressed
        switchStore(1);
        break;

      case KeyEvent.VK_F3: // if f3 was pressed
        switchStore(2);
        break;

      case KeyEvent.VK_F4: // if f4 was pressed
        switchStore(3);
        break;

      case KeyEvent.VK_D: // if d or right was pressed
      case KeyEvent.VK_RIGHT:
        if (currentPage != totalPages - 1) // if we are not on the last page
        {
          currentPage++;
          itemSelected = -1;
        }
        break;

      case KeyEvent.VK_A: // if a or left was pressed
      case KeyEvent.VK_LEFT:
        if (currentPage != 0) // if we are not on the first page
        {
          currentPage--;
          itemSelected = -1;
        }
        break;

      case KeyEvent.VK_W: // if w or up was pressed
      case KeyEvent.VK_UP:
        if (itemSelected == -1) // if no items currently selected
        {
          itemSelected = 0;
        } else // if an item was selected
        {
          itemSelected--;
          if (itemSelected < 0) // loop if at beginning of list
          {
            itemSelected = ITEMSPERPAGE - 1;
          }
        }

        break;

      case KeyEvent.VK_S: // if s or down was pressed
      case KeyEvent.VK_DOWN:
        itemSelected++;

        if (itemSelected >= ITEMSPERPAGE) // if at end of list, loop around
        {
          itemSelected = 0;
        }

        break;

      case KeyEvent.VK_ENTER: // if enter was pressed
        if (itemSelected == -1) // if no item was selected
        {
          break;
        }

        selected_item = itemsArray[itemSelected];

        option =
            JOptionPane.showConfirmDialog(
                this, ((!mode) ? "Buy " : "Sell ") + "for " + "$" + selected_item.getPrice() + "?");

        if (option == 0 && mode) // if they choose to buy
        {
          buyer = usersArray[0];
          switch (store) // change message based on value of store.
          {
            case 0:
              seller = usersArray[2];
              break;

            case 1:
              seller = usersArray[1];
              break;

            case 2:
              seller = usersArray[3];
              break;

            case 3:
              seller = usersArray[4];
              break;

            default:
              seller = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);

        } else if (option == 0 && mode) // if they choose to sell
        {
          seller = usersArray[0];

          switch (store) // change message based on value of store.
          {
            case 0:
              buyer = usersArray[2];
              break;

            case 1:
              buyer = usersArray[1];
              break;

            case 2:
              buyer = usersArray[3];
              break;

            case 3:
              buyer = usersArray[4];
              break;

            default:
              buyer = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);
        }

        itemSelected = -1;
        break;

      default:
        return;
    }

    repaint();
  }
  private void showPopup() {
    if (isEnabled()) {
      if (popup.isVisible()) {
        popup.setVisible(false);
      } else {
        Component[] components = popup.getComponents();
        if (components != null) {
          for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof Item) ((Item) components[i]).removeActionListener(this);
            else if (components[i] instanceof MenuItem) {
              Component[] subcomponents = ((MenuItem) components[i]).getComponents();
              for (int j = 0; j < components.length; j++) {
                if (components[j] instanceof Item)
                  ((Item) components[j]).removeActionListener(this);
              }
            }
          }
        }
        popup.removeAll();
        if (values == null) return;
        for (int i = 0; i < values.length; i++) {
          JMenuItem item = null;
          if (values[i] instanceof ListDescriptor) {
            ListDescriptor descriptor = (ListDescriptor) values[i];
            Icon icon = descriptor.getIcon();
            item = new Item(values[i].toString(), icon, i);
            item.addActionListener(this);
          } else if (values[i] instanceof AddElement) {
            AddElement element = (AddElement) values[i];
            Icon icon = element.getIcon();

            Object[] choiceValues = element.getChoiceValues();
            if (choiceValues != null) {
              item = new MenuItem(element.toString(), icon, i);
              for (int j = 0; j < choiceValues.length; j++) {
                if (choiceValues[j] == null) {
                  ((JMenu) item).addSeparator();
                  continue;
                }
                Item subItem = new Item(choiceValues[j].toString(), j);
                ((JMenu) item).add(subItem);
                subItem.setParentIndex(i);
                subItem.addActionListener(this);
              }
            } else {
              item = new Item(element.toString(), icon, i);
              item.addActionListener(this);
            }
            item.setVisible(element.isVisible());
            item.setEnabled(element.isEnabled());
          } else {
            if (values[i] != null) {
              item = new Item(values[i].toString(), i);
              item.addActionListener(this);
            }
          }
          if (item != null) {
            popup.add(item);
          } else popup.addSeparator();
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                AwtUtil.showPopupPanel(PopupMenuButton.this, popup);
              }
            });
      }
    }
  }
示例#21
0
  @Override
  public void mousePressed(MouseEvent e) {
    CustomButton buttonPressed; // Button that was pressed.
    String buttonName; // The name of the button.
    int option; // Option chosen by user.
    User buyer; // User object for buyer
    User seller; // User object for seller
    Item selected_item; // Item object for selected item

    if (help) // if in help mode
    {
      help = false;
      repaint();
      return;
    }

    wasItemSelected(e.getX(), e.getY());
    buttonPressed = CustomButton.wasPressed(e.getX(), e.getY());

    if (buttonPressed == null) // if no button was pressed
    {
      return;
    }

    buttonName = buttonPressed.getName();
    playAudio(-1);

    switch (buttonName) // handle event associated with button name
    {
      case "rightTab":
        currentPage++;
        itemSelected = -1;
        break;

      case "leftTab":
        currentPage--;
        itemSelected = -1;
        break;

      case "buyTab":
        mode = false;
        break;

      case "sellTab":
        mode = true;
        break;

      case "button":
        selected_item = itemsArray[itemSelected];

        option =
            JOptionPane.showConfirmDialog(
                this, ((!mode) ? "Buy " : "Sell ") + "for " + "$" + selected_item.getPrice() + "?");

        if (option == 0 && (!mode)) // if they choose to buy
        {
          buyer = usersArray[0];
          switch (store) // change message based on value of store.
          {
            case 0:
              seller = usersArray[2];
              break;

            case 1:
              seller = usersArray[1];
              break;

            case 2:
              seller = usersArray[3];
              break;

            case 3:
              seller = usersArray[4];
              break;

            default:
              seller = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);

        } else if (option == 0 && mode) // if they choose to sell
        {
          seller = usersArray[0];

          switch (store) // change message based on value of store.
          {
            case 0:
              buyer = usersArray[2];
              break;

            case 1:
              buyer = usersArray[1];
              break;

            case 2:
              buyer = usersArray[3];
              break;

            case 3:
              buyer = usersArray[4];
              break;

            default:
              buyer = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);
        }

        itemSelected = -1;
        break;

      case "nextStore":
        if (++store == NUMSTORES) // if we're on the last store, loop around
        {
          store = 0;
        }

        switchStore(store);
        break;

      case "sort":
        // something
        orderToSort =
            JOptionPane.showOptionDialog(
                this,
                "Sort by:",
                "Sort",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                SORTOPTIONS,
                null);

        break;

      case "help":
        help = true;
        break;

      default:
    }

    repaint();
  }