/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Tavolo.java
*
* Created on 11-mar-2010, 20.12.36
*/
package blackjack.graphics;
import blackjack.Shuffler;
import blackjack.Card;
import blackjack.Player;
import blackjack.Sound;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.ArrayList;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiUnavailableException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/**
*
* @author paolo
*/
public class Tavolo
extends javax.
swing.
JFrame {
private final String estensione
= ".png";
private Shuffler banco;
private int soldi;
private Player player;
private Sound musica;
private void initComboBox() {
//InputStream path = getClass().getResourceAsStream("/blackjack/music/");
// BufferedReader buff = new BufferedReader(new InputStreamReader(path));
ArrayList<String> musiche = new ArrayList<String>();
/*try {
System.out.println(buff.ready() + " " + buff + " " + path);
while (buff.ready()) {
musiche.add(buff.readLine());
}
} catch (IOException ex) {
}*/
//musiche=dir.list();
musiche.add("AlexBritti-UnaSuUnMilione");
musiche.add("Beatles-Imagine");
musiche.add("Beatles-Yesterday");
musiche.add("DeAndre-BallataDell'amoreCieco");
musiche.add("DeAndre-DonRaffae");
musiche.add("DeAndre-FiumeSandCreek");
musiche.add("DeAndre-Geordie");
musiche.add("DeAndre-IlBombarolo");
musiche.add("DeAndre-LaCittaVecchia");
musiche.add("DeAndre-UnGiudice");
musiche.add("DeanMartin-That'sAmore");
musiche.add("LisaStansfield-WhatAWonderfulWorld");
musiche.add("MichaelBuble-ComeFlyWithMe");
musiche.add("MichaelBuble-Don'tGet");
musiche.add("MichaelBuble-SpidermanTheme");
musiche.add("P.DiCapri-Champagne");
musiche.add("Queen-WeAreTheChampions");
musiche.add("Queen-WeWillRockYou");
musiche.add("TheDoors-LightMyFire");
musiche.add("TheDoors-RidersOnStorm");
musiche.add("Tv-Animaniacs");
musiche.add("Tv-Flintstones");
musiche.add("Tv-HappyDays");
for (int i = 0; i < musiche.size(); i++) {
String item
= musiche.
get(i
).
replaceAll(".mid",
"");
this.listComboBox.addItem(item);
}
}
private void startAudio() {
this.musica.stopAudio();
try {
this.musica.startAudio("/blackjack/music/" + this.listComboBox.getSelectedItem() + ".mid");
}
}
private void stopAudio() {
this.musica.stopAudio();
}
@Override
if (e.
getKeyCode() == KeyEvent.
VK_ESCAPE) {
close();
} else if (e.
getKeyCode() == KeyEvent.
VK_F1) {
newGame();
} else if (e.
getKeyCode() == KeyEvent.
VK_M) {
JOptionPane.
showMessageDialog(rootPane,
"Ringraziamento speciale a Mariangela, che mi ha dato l'idea del KeyListener!");
} else if (e.
getKeyCode() == KeyEvent.
VK_L) {
JOptionPane.
showMessageDialog(rootPane,
"Ringraziamento speciale a Lorenzo, che mi ha ispirato col suo Black Jack!l");
} else if (e.
getKeyCode() == KeyEvent.
VK_O) {
JOptionPane.
showMessageDialog(rootPane,
"Ringraziamento speciale al prof. Oliveto Rocco che mi ha supportato e soprattutto sopportato dandomi preziosi consigli!");
} else if (e.
getKeyCode() == KeyEvent.
VK_F) {
JOptionPane.
showMessageDialog(rootPane,
"Ringraziamento speciale ai miei amici che mi hanno aiutato a testare questo gioco!");
}
}
}
@Override
this.trucco = this.trucco + e.getKeyChar();
if (e.getKeyChar() == 'r') {
this.checkTrucco();
}
}
public void checkTrucco() {
char[] trick = this.trucco.toLowerCase().toCharArray();
if (trick.length >= 5) {
for (int i = trick.length - 5; i < trick.length; i++) {
controlla = controlla + trick[i];
}
if (controlla.equals("ungar")) {
player.setMoney(player.getMoney() + 1000);
howMuchMoneyLabel.setText(player.getMoney() + "");
this.trucco = "";
}
}
}
}
/** Creates new form Tavolo */
public Tavolo
(String title,
boolean pMusica
) {
initComponents();
this.
setIconImage(new ImageIcon(getClass
().
getResource("/blackjack/graphics/images/icon.jpg")).
getImage());
this.setFocusable(true);
addKeyListener(new Trucchi());
addKeyListener(new Tasti());
this.banco = new Shuffler();
this.setTitle(title);
this.insuranceButton.setVisible(false);
this.cardButton.setEnabled(false);
this.standButton.setEnabled(false);
char[] tit = title.toCharArray();
for (int i = 12; i < title.length(); i++) {
nome = nome + tit[i];
}
this.playerLabel.setText(nome);
this.player = new Player();
this.moneyLabel.setText(this.player.getMoney() + "");
this.betButton.setEnabled(false);
this.panel2.setVisible(false);
this.initComboBox();
try {
this.musica = new Sound();
}
if (pMusica) {
this.startAudio();
} else {
this.playButton.setText("Play");
}
}
private void close() {
}
private void drawCard() {
Card[] carte = this.banco.getCards(0);
for (int i = 0; i < carte.length; i++) {
card
[i
] = new ImageIcon(getClass
().
getResource("/blackjack/graphics/images/" + carte
[i
].
getNumber() + carte
[i
].
getSuit() + this.
estensione));
}
this.card1.setIcon(card[0]);
this.card2.setIcon(card[1]);
this.card3.setIcon(card[2]);
this.card4.setIcon(card[3]);
this.card5.setIcon(card[4]);
carte = this.banco.getCards(1);
for (int i = 0; i < carte.length; i++) {
card
[i
] = new ImageIcon(getClass
().
getResource("/blackjack/graphics/images/" + carte
[i
].
getNumber() + carte
[i
].
getSuit() + this.
estensione));
if (carte[i].isCover()) {
card
[i
] = new ImageIcon(getClass
().
getResource("/blackjack/graphics/images/back" + this.
estensione));
}
}
this.card6.setIcon(card[0]);
this.card7.setIcon(card[1]);
this.card8.setIcon(card[2]);
this.card9.setIcon(card[3]);
this.card10.setIcon(card[4]);
if (this.banco.isInsurancePossible() && !this.banco.isInsurance()) {
JOptionPane.
showMessageDialog(rootPane,
"Puoi effettuare l'insurance, scommettendo la metà della puntata sul BlackJack del banco!");
this.insuranceButton.setVisible(true);
}
this.playerPoint.setText(this.banco.getPoint(0) + "");
this.bancoPoint.setText(this.banco.getPoint(1) + "");
}
private void newGame() {
this.player = new Player();
this.reset();
}
private void reset() {
this.twentyButton.setEnabled(true);
this.fiftyButton.setEnabled(true);
this.oneHundredButton.setEnabled(true);
this.twoHundredButton.setEnabled(true);
this.fiveHundredButton.setEnabled(true);
this.oneThousandButton.setEnabled(true);
this.insuranceButton.setVisible(false);
this.betButton.setEnabled(false);
this.howMuchBetLabel.setText("-");
this.card1.setIcon(null);
this.card2.setIcon(null);
this.card3.setIcon(null);
this.card4.setIcon(null);
this.card5.setIcon(null);
this.card6.setIcon(null);
this.card7.setIcon(null);
this.card8.setIcon(null);
this.card9.setIcon(null);
this.card10.setIcon(null);
this.bancoPoint.setText("0");
this.playerPoint.setText("0");
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.banco = new Shuffler();
this.banco.setBet(0);
this.panel2.setVisible(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
panel
= new javax.
swing.
JPanel();
card1
= new javax.
swing.
JLabel();
card2
= new javax.
swing.
JLabel();
card3
= new javax.
swing.
JLabel();
card4
= new javax.
swing.
JLabel();
card5
= new javax.
swing.
JLabel();
card6
= new javax.
swing.
JLabel();
card7
= new javax.
swing.
JLabel();
card8
= new javax.
swing.
JLabel();
card9
= new javax.
swing.
JLabel();
card10
= new javax.
swing.
JLabel();
standButton
= new javax.
swing.
JButton();
cardButton
= new javax.
swing.
JButton();
insuranceButton
= new javax.
swing.
JButton();
bancoLabel
= new javax.
swing.
JLabel();
bancoPoint
= new javax.
swing.
JLabel();
playerLabel
= new javax.
swing.
JLabel();
playerPoint
= new javax.
swing.
JLabel();
label
= new javax.
swing.
JLabel();
moneyLabel
= new javax.
swing.
JLabel();
howMuchMoneyLabel
= new javax.
swing.
JLabel();
twentyButton
= new javax.
swing.
JButton();
fiftyButton
= new javax.
swing.
JButton();
oneHundredButton
= new javax.
swing.
JButton();
twoHundredButton
= new javax.
swing.
JButton();
fiveHundredButton
= new javax.
swing.
JButton();
oneThousandButton
= new javax.
swing.
JButton();
betLabel
= new javax.
swing.
JLabel();
howMuchBetLabel
= new javax.
swing.
JLabel();
betButton
= new javax.
swing.
JButton();
panel2
= new javax.
swing.
JPanel();
responseLabel
= new javax.
swing.
JLabel();
continueButton
= new javax.
swing.
JButton();
instructionLabel
= new javax.
swing.
JLabel();
listLabel
= new javax.
swing.
JLabel();
playButton
= new javax.
swing.
JButton();
setResizable(false);
panel.
setBackground(new java.
awt.
Color(108, 219, 116
));
card10.
setBorder(javax.
swing.
BorderFactory.
createLineBorder(new java.
awt.
Color(0, 0, 0
)));
standButton.setText("Stai!");
standButton.setFocusable(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
standButtonActionPerformed(evt);
}
});
cardButton.setText("Carta!");
cardButton.setFocusable(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
cardButtonActionPerformed(evt);
}
});
insuranceButton.setText("Insurance!");
insuranceButton.setFocusable(false);
insuranceButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
insuranceButtonActionPerformed(evt);
}
});
bancoLabel.setText("Banco");
bancoPoint.setText("0");
playerLabel.setText("jLabel13");
playerPoint.setText("0");
label.setText("Punta:");
moneyLabel.setText("Soldi:");
howMuchMoneyLabel.setText("500");
twentyButton.setText("20");
twentyButton.setFocusable(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
twentyButtonActionPerformed(evt);
}
});
fiftyButton.setText("50");
fiftyButton.setFocusable(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
fiftyButtonActionPerformed(evt);
}
});
oneHundredButton.setText("100");
oneHundredButton.setFocusable(false);
oneHundredButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
oneHundredButtonActionPerformed(evt);
}
});
twoHundredButton.setText("200");
twoHundredButton.setFocusable(false);
twoHundredButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
twoHundredButtonActionPerformed(evt);
}
});
fiveHundredButton.setText("500");
fiveHundredButton.setFocusable(false);
fiveHundredButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
fiveHundredButtonActionPerformed(evt);
}
});
oneThousandButton.setText("1000");
oneThousandButton.setFocusable(false);
oneThousandButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
oneThousandButtonActionPerformed(evt);
}
});
betLabel.setText("Bet:");
howMuchBetLabel.setText("-");
betButton.setText("Punta!");
betButton.setFocusable(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
betButtonActionPerformed(evt);
}
});
panel2.
setBackground(new java.
awt.
Color(51, 94, 54
));
panel2.
setBorder(new javax.
swing.
border.
SoftBevelBorder(javax.
swing.
border.
BevelBorder.
RAISED,
new java.
awt.
Color(51, 94, 54
), java.
awt.
Color.
black,
new java.
awt.
Color(51, 94, 54
),
new java.
awt.
Color(31, 19, 19
)));
responseLabel.
setFont(new java.
awt.
Font("DejaVu Sans", 1, 24
)); // NOI18N
responseLabel.
setHorizontalAlignment(javax.
swing.
SwingConstants.
CENTER);
responseLabel.setText("jLabel20");
continueButton.setText("Continua a giocare!");
continueButton.setFocusable(false);
continueButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
continueButtonActionPerformed(evt);
}
});
instructionLabel.setText("Premere ESC per uscire, F1 per un nuovo gioco");
javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
panel2.setLayout(panel2Layout);
panel2Layout.setHorizontalGroup(
panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panel2Layout.createSequentialGroup()
.addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panel2Layout.createSequentialGroup()
.addContainerGap()
.
addComponent(responseLabel, javax.
swing.
GroupLayout.
DEFAULT_SIZE, 301,
Short.
MAX_VALUE))
.addGroup(panel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(instructionLabel))
.addGroup(panel2Layout.createSequentialGroup()
.addGap(90, 90, 90)
.addComponent(continueButton)))
.addContainerGap())
);
panel2Layout.setVerticalGroup(
panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(responseLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(continueButton)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.addComponent(instructionLabel))
);
listLabel.setText("Elenco canzoni disponibili:");
listLabel.setFocusable(false);
listComboBox.setFocusable(false);
}
public void popupMenuWillBecomeInvisible
(javax.
swing.
event.
PopupMenuEvent evt
) {
listComboBoxPopupMenuWillBecomeInvisible(evt);
}
public void popupMenuWillBecomeVisible
(javax.
swing.
event.
PopupMenuEvent evt
) {
}
});
playButton.setText("Stop");
playButton.setFocusable(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
playButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
panel.setLayout(panelLayout);
panelLayout.setHorizontalGroup(
panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addComponent(label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(oneHundredButton)
.addComponent(twentyButton)
.addComponent(fiveHundredButton)))
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(moneyLabel)
.addComponent(betLabel))
.addGap(18, 18, 18)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(howMuchBetLabel)
.addComponent(howMuchMoneyLabel))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(fiftyButton)
.addComponent(twoHundredButton)
.addComponent(oneThousandButton)))
.addComponent(betButton)))
.addGroup(panelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(listLabel))
.addGroup(panelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(playButton))
.addGroup(panelLayout.createSequentialGroup()
.addContainerGap()
.
addComponent(listComboBox, 0, 193,
Short.
MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(panelLayout.createSequentialGroup()
.addComponent(insuranceButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cardButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(standButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16))
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(playerLabel)
.addComponent(playerPoint))
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, 128,
Short.
MAX_VALUE)
.addComponent(card5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addComponent(bancoLabel)
.addGap(61, 61, 61))
.addGroup(panelLayout.createSequentialGroup()
.
addComponent(bancoPoint, javax.
swing.
GroupLayout.
DEFAULT_SIZE, 162,
Short.
MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addComponent(card10, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card9, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card8, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card7, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(card6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(168, 168, 168))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
.
addContainerGap(386,
Short.
MAX_VALUE)
.addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(354, 354, 354))
);
panelLayout.setVerticalGroup(
panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(card6, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card7, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card8, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card9, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card10, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, 109,
Short.
MAX_VALUE)
.addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(card1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card3, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card4, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(card5, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(insuranceButton)
.addComponent(cardButton)
.addComponent(standButton))
.addContainerGap())
.addGroup(panelLayout.createSequentialGroup()
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bancoLabel)
.addComponent(listLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelLayout.createSequentialGroup()
.addComponent(bancoPoint)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, 436,
Short.
MAX_VALUE)
.addComponent(playerLabel))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
.addComponent(listComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(playButton)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, 387,
Short.
MAX_VALUE)
.addComponent(betButton)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(playerPoint)
.addComponent(betLabel)
.addComponent(howMuchBetLabel))
.addGap(31, 31, 31)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(moneyLabel)
.addComponent(howMuchMoneyLabel))
.addGap(18, 18, 18)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(label)
.addComponent(twentyButton)
.addComponent(fiftyButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(oneHundredButton)
.addComponent(twoHundredButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(fiveHundredButton)
.addComponent(oneThousandButton))
.addGap(9, 9, 9))))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(panel, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(panel, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void twentyButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_twentyButtonActionPerformed
if (20 <= this.player.getMoney()) {
this.banco.setBet(this.banco.getBet() + 20);
this.player.setMoney(this.player.getMoney() - 20);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
} else {
this.banco.setBet(this.banco.getBet() + this.player.getMoney());
this.player.setMoney(0);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
}
}//GEN-LAST:event_twentyButtonActionPerformed
private void fiftyButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_fiftyButtonActionPerformed
if (50 <= this.player.getMoney()) {
this.banco.setBet(this.banco.getBet() + 50);
this.player.setMoney(this.player.getMoney() - 50);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
} else {
this.banco.setBet(this.banco.getBet() + this.player.getMoney());
this.player.setMoney(0);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
}
}//GEN-LAST:event_fiftyButtonActionPerformed
private void oneHundredButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_oneHundredButtonActionPerformed
if (100 <= this.player.getMoney()) {
this.banco.setBet(this.banco.getBet() + 100);
this.player.setMoney(this.player.getMoney() - 100);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
} else {
this.banco.setBet(this.banco.getBet() + this.player.getMoney());
this.player.setMoney(0);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
}
}//GEN-LAST:event_oneHundredButtonActionPerformed
private void twoHundredButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_twoHundredButtonActionPerformed
if (200 <= this.player.getMoney()) {
this.banco.setBet(this.banco.getBet() + 200);
this.player.setMoney(this.player.getMoney() - 200);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
} else {
this.banco.setBet(this.banco.getBet() + this.player.getMoney());
this.player.setMoney(0);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
}
}//GEN-LAST:event_twoHundredButtonActionPerformed
private void fiveHundredButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_fiveHundredButtonActionPerformed
if (500 <= this.player.getMoney()) {
this.banco.setBet(this.banco.getBet() + 500);
this.player.setMoney(this.player.getMoney() - 500);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
} else {
this.banco.setBet(this.banco.getBet() + this.player.getMoney());
this.player.setMoney(0);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
}
}//GEN-LAST:event_fiveHundredButtonActionPerformed
private void oneThousandButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_oneThousandButtonActionPerformed
if (1000 <= this.player.getMoney()) {
this.banco.setBet(this.banco.getBet() + 1000);
this.player.setMoney(this.player.getMoney() - 1000);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
} else {
this.banco.setBet(this.banco.getBet() + this.player.getMoney());
this.player.setMoney(0);
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.howMuchBetLabel.setText(this.banco.getBet() + "");
this.betButton.setEnabled(true);
}
}//GEN-LAST:event_oneThousandButtonActionPerformed
private void betButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_betButtonActionPerformed
this.twentyButton.setEnabled(false);
this.fiftyButton.setEnabled(false);
this.oneHundredButton.setEnabled(false);
this.twoHundredButton.setEnabled(false);
this.fiveHundredButton.setEnabled(false);
this.oneThousandButton.setEnabled(false);
this.betButton.setEnabled(false);
this.standButton.setEnabled(true);
this.cardButton.setEnabled(true);
this.banco.start();
this.drawCard();
if (banco.isBlackJack(0)) {
this.standButtonActionPerformed(evt);
}
}//GEN-LAST:event_betButtonActionPerformed
private void standButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_standButtonActionPerformed
this.banco.play();
this.standButton.setEnabled(false);
this.cardButton.setEnabled(false);
this.drawCard();
this.player.setMoney(this.player.getMoney() + this.banco.pay());
this.panel2.setVisible(true);
if (this.banco.isWinner() || (this.banco.isBlackJack(0) && !this.banco.isBlackJack(1))) {
testo = "Hai vinto " + this.banco.pay() + "!!!";
} else {
testo = "Mi dispiace hai perso!";
}
this.responseLabel.setText(testo);
}//GEN-LAST:event_standButtonActionPerformed
private void cardButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_cardButtonActionPerformed
this.banco.card(0);
this.drawCard();
if (this.banco.getPoint(0) > 21 || this.banco.getNumCarte(0) == 5) {
this.standButtonActionPerformed(evt);
}
}//GEN-LAST:event_cardButtonActionPerformed
private void continueButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_continueButtonActionPerformed
this.reset();
this.panel2.setVisible(false);
if (this.player.getMoney() == 0) {
}
}//GEN-LAST:event_continueButtonActionPerformed
private void insuranceButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_insuranceButtonActionPerformed
if (!this.banco.isInsurance() && this.player.getMoney() > this.banco.getBet() / 2) {
this.player.setMoney(this.player.getMoney() - (this.banco.getBet() / 2));
this.howMuchMoneyLabel.setText(this.player.getMoney() + "");
this.banco.setIns(true);
if (this.banco.isBlackJack(1)) {
this.banco.setInsurance(true);
}
}
}//GEN-LAST:event_insuranceButtonActionPerformed
private void listComboBoxPopupMenuWillBecomeInvisible
(javax.
swing.
event.
PopupMenuEvent evt
) {//GEN-FIRST:event_listComboBoxPopupMenuWillBecomeInvisible
this.startAudio();
this.playButton.setText("Stop");
}//GEN-LAST:event_listComboBoxPopupMenuWillBecomeInvisible
private void playButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_playButtonActionPerformed
if (this.playButton.getText().equals("Stop")) {
this.stopAudio();
this.playButton.setText("Play");
} else {
this.startAudio();
this.playButton.setText("Stop");
}
}//GEN-LAST:event_playButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.
swing.
JLabel bancoLabel
;
private javax.
swing.
JLabel bancoPoint
;
private javax.
swing.
JButton betButton
;
private javax.
swing.
JLabel betLabel
;
private javax.
swing.
JLabel card1
;
private javax.
swing.
JLabel card10
;
private javax.
swing.
JLabel card2
;
private javax.
swing.
JLabel card3
;
private javax.
swing.
JLabel card4
;
private javax.
swing.
JLabel card5
;
private javax.
swing.
JLabel card6
;
private javax.
swing.
JLabel card7
;
private javax.
swing.
JLabel card8
;
private javax.
swing.
JLabel card9
;
private javax.
swing.
JButton cardButton
;
private javax.
swing.
JButton continueButton
;
private javax.
swing.
JButton fiftyButton
;
private javax.
swing.
JButton fiveHundredButton
;
private javax.
swing.
JLabel howMuchBetLabel
;
private javax.
swing.
JLabel howMuchMoneyLabel
;
private javax.
swing.
JLabel instructionLabel
;
private javax.
swing.
JButton insuranceButton
;
private javax.
swing.
JLabel label
;
private javax.
swing.
JLabel listLabel
;
private javax.
swing.
JLabel moneyLabel
;
private javax.
swing.
JButton oneHundredButton
;
private javax.
swing.
JButton oneThousandButton
;
private javax.
swing.
JPanel panel
;
private javax.
swing.
JPanel panel2
;
private javax.
swing.
JButton playButton
;
private javax.
swing.
JLabel playerLabel
;
private javax.
swing.
JLabel playerPoint
;
private javax.
swing.
JLabel responseLabel
;
private javax.
swing.
JButton standButton
;
private javax.
swing.
JButton twentyButton
;
private javax.
swing.
JButton twoHundredButton
;
// End of variables declaration//GEN-END:variables
}