/** * actionPerformed - implementation of the ActionListener interface, providing actions to the two * buttons in the dialog box * * @param e - the ActionEvent fired by the JVM, used to determine the source of the click */ public void actionPerformed(ActionEvent e) { if (e.getSource() == enterButton) { try { int bet = Integer.parseInt(betField.getText()); if (bet < 1) { // make sure the bet is high enough JOptionPane.showMessageDialog( null, "Your bet must be one or higher. Please enter a valid bet.", "Invalid Bet", JOptionPane.ERROR_MESSAGE); return; } else if (bet > Math.min( parent.getBettingLimit(), parent.getCurrentPlayer().getMoney())) { // don't let user go over what they have JOptionPane.showMessageDialog( null, "You cannot bet that high. The maximum you can bet is $" + Math.min(parent.getBettingLimit(), parent.getCurrentPlayer().getMoney()) + ".\nPlease enter a valid bet.", "Invalid Bet", JOptionPane.ERROR_MESSAGE); return; } parent .getCurrentPlayer() .setBet(bet); // create the bet, and subtract it from the money amount parent.getCurrentPlayer().setMoney(parent.getCurrentPlayer().getMoney() - bet); setVisible(false); // dispose of this dialog } catch (NumberFormatException nfe) { // if user doesn't enter a correct number JOptionPane.showMessageDialog( null, "Invalid entry for bet.\nPlease enter a valid amount to bet.", "Invalid Bet", JOptionPane.ERROR_MESSAGE); return; } } else if (e.getSource() == skipHandButton) { // make player inactive for this hand parent.getCurrentPlayer().setActive(false); parent.getCurrentPlayer().setBet(0); setVisible(false); // dispose of this dialog } }