/** * When the player click the BET button, check the input validity and process. * * @param e */ @Override public void mouseClicked(MouseEvent e) { if (betButton.isEnabled()) { int bet = 0; try { bet = Integer.parseInt(betInput.getText()); if (bet <= 0 || bet > player.getMoney()) throw null; } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Invalid bet"); betInput.setText(null); betInput.requestFocusInWindow(); return; } int d1 = dealer.makeDecision(); if (d1 != -1) { dealer.changeCard(d1, genNewCard()); int d2 = dealer.makeDecision(); if (d2 != -1) dealer.changeCard(d2, genNewCard()); } player.makeBet(bet); for (Card card : player.getCards()) card.showFront(); for (Card card : player.getCards()) card.addMouseListener(new ReplaceListener()); betButton.setEnabled(false); resultButton.setEnabled(true); repaint(); } }
/** * When the player click a card for replacing, process and change the card. * * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if (numReplaced < 2) { Card nCard = genNewCard(); nCard.addMouseListener(this); player.changeCard(player.getCards().indexOf(e.getSource()), nCard); ++numReplaced; repaint(); } }