@Override public void paint(Graphics g) { super.paint(g); connectUsers("Select * from users"); CustomButton.setGraphics(g); ScaledPoint.setWindowDimensions(getWidth(), getHeight()); if (help) // display help message { showHelp(g); return; } // Draw main GUI components drawStoreBG(g); drawStoreName(g); drawStoreImage(g); drawStoreMessage(g); drawInventory(g); drawBalance(g); drawPageIndicator(g); deactivateButtons(); CustomButton.draw(); }
private void deactivateButtons() // POST: Deactivates buttons that should not be pressed. { if (currentPage == 0) // if we are at the first page, disable leftTab { leftTab.deactivate(); } else // otherwise activate it { leftTab.activate(); } if (currentPage == totalPages - 1) // if we are at the last page, disable rightTab { rightTab.deactivate(); } else // otherwise activate it { rightTab.activate(); } if (itemSelected == -1) // if no item has been selected { buySellButton.deactivate(); } else // otherwise activate it { buySellButton.activate(); } if (!mode) // if we are in buying mode { buyTab.deactivate(); sellTab.activate(); } else // if we are in selling mode { sellTab.deactivate(); buyTab.activate(); } }
@Override public void mouseReleased(MouseEvent arg0) { CustomButton.depress(); repaint(); }
@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(); }