import java.util.Random;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PushCounter extends JApplet implements ActionListener
{
private int APPLET_WIDTH = 2000, APPLET_HEIGHT = 355;
private int pushes;
private JLabel label, DEALERCARD,PLAYERHAND,PLAYERTOTAL,SPACER,SPACER2;
private JButton hit= new JButton ("Hit");
private JButton stand= new JButton ("Stand");
public void init()
{
String [] Deck = {"Ace of spades","Ace of hearts","Ace of clubs","Ace of diamonds",
"2 of spades", "2 of clubs", "2 of diamonds","2 of hearts",
"3 of spades", "3 of diamonds","3 of hearts", "3 of clubs",
"4 of spades", "4 of hearts", "4 of clubs", "4 of diamonds",
"5 of hearts", "5 of clubs", "5 of diamonds","5 of spades",
"6 of spades", "6 of diamonds","6 of hearts", "6 of clubs",
"7 of spades", "7 of hearts", "7 of clubs", "7 of diamonds",
"8 of hearts", "8 of clubs", "8 of diamonds", "8 of spades",
"9 of hearts", "9 of clubs", "9 of diamonds", "9 of spades",
"10 of hearts", "10 of clubs", "10 of diamonds", "10 of spades",
"Jack of hearts", "Jack of clubs", "Jack of diamonds", "Jack of spades",
"Queen of hearts", "Queen of clubs", "Queen of diamonds", "Queen of spades",
"King of hearts", "King of clubs", "King of diamonds", "King of spades"};
int [] Value = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10, 10,10,10,10,10,10,10};
DEALERCARD = new JLabel ("Dealer's hand: ");
PLAYERHAND = new JLabel ("Your hand: ");
PLAYERTOTAL = new JLabel ("Your total: ");
SPACER = new JLabel (" ");
SPACER2 = new JLabel (" ");
Container cp = getContentPane();
cp.setBackground (Color.cyan);
cp.setLayout (new FlowLayout());
Random generator = new Random();
int a,b,c,d;
a = generator.nextInt(52);
b = generator.nextInt(52);
c = generator.nextInt(52);
d = generator.nextInt(52);
while (Deck[a].equals(Deck[b]) ||Deck[a].equals(Deck[c]) ||Deck[a].equals(Deck[d])||
Deck[b].equals(Deck[c]) ||Deck[b].equals(Deck[d]) ||
Deck[c].equals(Deck[d]) )
{ a = generator.nextInt(52);
b = generator.nextInt(52);
c = generator.nextInt(52);
d = generator.nextInt(52);
}
DEALERCARD.setText ("Dealer's hand: "+Deck[a]);
PLAYERHAND.setText ("Your hand: "+Deck[b]+" and "+Deck[c]);
PLAYERTOTAL.setText ("Your total: "+(Value[b]+Value[c]));
if (Value[b]+Value[c] ==21){label.setText("You Win!");}
label = new JLabel ("----");
cp.add (DEALERCARD);
cp.add (SPACER);
cp.add (PLAYERHAND);
cp.add (SPACER2);
cp.add (PLAYERTOTAL);
cp.add (hit);
cp.add (stand);
cp.add (label);
hit.addActionListener(this);
stand.addActionListener(this);
setSize (APPLET_WIDTH, APPLET_HEIGHT);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == hit) {
Random generator = new Random();
int f = generator.nextInt(52);
PLAYERHAND.setText ("Your hand: "+Deck[b]+" and "+Deck[c]+" and "+Deck[f] );
}
if (e.getSource() == stand) {
label.setText ("Blah");
}}}