@Override public void updatePlayer(ArrayList<PlayerStateEvent> playerStates) { int currentPlayerAccount = 0; int jailCardCount = 0; for (PlayerStateEvent pse : playerStates) { if (pse.hasTurnToken()) { currentPlayerAccount = pse.getAccount(); jailCardCount = pse.getJailCard(); } } int buttonCount = epi.getButtonCount(); for (int i = 0; i < buttonCount; i++) { if (epi.getButtonAtIndex(i).getAmount() > currentPlayerAccount) epi.getButtonAtIndex(i).setEnabled(false); else if (epi.getButtonAtIndex(i).getAmount() > 0) epi.getButtonAtIndex(i).setEnabled(true); // if the amount is -100 this signals the button is for using a jail card if (epi.getButtonAtIndex(i).getAmount() == -100) { if (jailCardCount < 1) epi.getButtonAtIndex(i).setEnabled(false); else epi.getButtonAtIndex(i).setEnabled(true); } } }
public void changePanel(EventPanelInfo epi) { JPanel newButtonPanel = new JPanel(); label.setText("\n" + epi.getText()); // format the text SimpleAttributeSet bSet = new SimpleAttributeSet(); StyleConstants.setAlignment(bSet, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(bSet, "lucida typewriter bold"); StyleConstants.setFontSize(bSet, 24); StyledDocument doc = label.getStyledDocument(); doc.setParagraphAttributes(0, doc.getLength(), bSet, false); System.out.println("label.getText(): " + label.getText()); int buttonCount = epi.getButtonCount(); for (int i = 0; i < buttonCount; i++) { JButton button = epi.getButtonAtIndex(i); newButtonPanel.add(button); } master.remove(buttonPanel); buttonPanel = newButtonPanel; master.add(label, BorderLayout.CENTER); master.add(buttonPanel, BorderLayout.SOUTH); }