Applet Urgent Help Plz
Hello Everyone, im having a major problem with this applet.I am trying to create a Black Jack card game to play around.It is compiling with no errors however the applet doesnt seem to get initialised thus it is not possible to be viewed in the applet viewer. What im trying to achieve is being able to draw 2 cards in the deck. Ever since i tried to use the showBlackjackScore() method as well as the init()method things started to get serious.These methods implementations were taken from: http://nifty.stanford.edu/2004/EstellCardGame/code.html were the Card, Deck, Hand, Rank, and Suit classes are also implemented, and are used with this program. Would appreciate any help! Other than that, the Gui is of my own and is a really nice example for ideas in your future java programs.Thanks in Advance!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
publicclass BlackJackClientextends JApplet
{
private Deck cardDeck;
private BlackjackHand myHand;
privatefinalint SIZE_OF_HAND = 2;
privatefinal String directory ="cards/";
private JLabel[] handLbl =new JLabel[ SIZE_OF_HAND ];
private Container container;
private JPanel panel1,panel2,Flow,Opponent,Player;
private JPanel cardsTop,cardsBottom;
private JLabel Player_Status;
private JLabel top_card1,top_card2,top_card3,top_card4,top_card5;
private JLabel bottom_card1,bottom_card2,bottom_card3,bottom_card4,bottom_card5;
private TitledBorder opponent,player;
private TitledBorder Cr1,Cr2,Cr3,Cr4,Cr5;
private TitledBorder B1,B2,B3,B4,B5;
private JPanel box1,box2,box3,box4,box5,box6,box7,box8,box9,box10;
private JTextArea Messages;
private JButton Hit,Stand,JButton1;
private JLabel scoreLbl;
public BlackJackClient()//CONSTRUCTOR
{
container=getContentPane();
container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS));
scoreLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
scoreLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
getContentPane().add(scoreLbl);
scoreLbl.setForeground(java.awt.Color.black);
scoreLbl.setFont(new Font("Dialog", Font.BOLD, 64));
scoreLbl.setBounds(252,48,103,88);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++PANELS
JPanel p =new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
Opponent=new JPanel();
Player=new JPanel();
cardsTop=new JPanel(new FlowLayout(FlowLayout.CENTER,10,15));
cardsBottom=new JPanel(new FlowLayout(FlowLayout.CENTER,10,15));
panel1=new JPanel();
panel2=new JPanel();
box1=new JPanel();
box2=new JPanel();
box3=new JPanel();
box4=new JPanel();
box5=new JPanel();
box6=new JPanel();
box7=new JPanel();
box8=new JPanel();
box9=new JPanel();
box10=new JPanel();
Flow=new JPanel(new FlowLayout(FlowLayout.RIGHT,3,0));
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
JLabel label=new JLabel("Welcome To BlackJack 21",SwingConstants.CENTER);
label.setForeground(Color.white);
label.setFont(new Font("Futura",Font.BOLD,19));
panel1.add(label);
panel1.setBackground(Color.black);
Icon card1=new ImageIcon("Trapula/c1.png");
top_card1=new JLabel(card1);
Icon card2=new ImageIcon("Trapula/d1.png");
top_card2=new JLabel(card2);
Icon card3=new ImageIcon("Trapula/h1.png");
top_card3=new JLabel(card3);
Icon card4=new ImageIcon("Trapula/s1.png");
top_card4=new JLabel(card4);
Icon card5=new ImageIcon("Trapula/ck.png");
top_card5=new JLabel(card5);
box1.add(top_card1);
cardsTop.add(box1);
box2.add(top_card2);
cardsTop.add(box2);
box3.add(top_card3);
cardsTop.add(box3);
box4.add(top_card4);
cardsTop.add(box4);
box5.add(top_card5);
cardsTop.add(box5);
Cr1 =new TitledBorder(new LineBorder(Color.black,2),"");
box1.setBorder(Cr1);
box1.setBackground(Color.gray);
Cr2 =new TitledBorder(new LineBorder(Color.black,2),"");
box2.setBorder(Cr2);
box2.setBackground(Color.gray);
Cr3 =new TitledBorder(new LineBorder(Color.black,2),"");
box3.setBorder(Cr3);
box3.setBackground(Color.gray);
Cr4 =new TitledBorder(new LineBorder(Color.black,2),"");
box4.setBorder(Cr4);
box4.setBackground(Color.gray);
Cr5 =new TitledBorder(new LineBorder(Color.black,2),"");
box5.setBorder(Cr5);
box5.setBackground(Color.gray);
opponent=new TitledBorder(new LineBorder(Color.black,5),"Opponent");
Opponent.setBorder(opponent);
Opponent.add(cardsTop);
Opponent.setBackground(Color.green);
cardsTop.setBackground(Color.green);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Icon card6=new ImageIcon("Trapula/s4.png");
bottom_card1=new JLabel(card6);
Icon card7=new ImageIcon("Trapula/s5.png");
bottom_card2=new JLabel(card7);
Icon card8=new ImageIcon("Trapula/s6.png");
bottom_card3=new JLabel(card8);
Icon card9=new ImageIcon("Trapula/s7.png");
bottom_card4=new JLabel(card9);
Icon card10=new ImageIcon("Trapula/s8.png");
bottom_card5=new JLabel(card10);
box6.add(bottom_card1);
cardsBottom.add(box6);
box7.add(bottom_card2);
cardsBottom.add(box7);
box8.add(bottom_card3);
cardsBottom.add(box8);
box9.add(bottom_card4);
cardsBottom.add(box9);
box10.add(bottom_card5);
cardsBottom.add(box10);
B1=new TitledBorder(new LineBorder(Color.black,2),"");
box6.setBorder(B1);
box6.setBackground(Color.gray);
B2=new TitledBorder(new LineBorder(Color.black,2),"");
box7.setBorder(B2);
box7.setBackground(Color.gray);
B3=new TitledBorder(new LineBorder(Color.black,2),"");
box8.setBorder(B3);
box8.setBackground(Color.gray);
B4=new TitledBorder(new LineBorder(Color.black,2),"");
box9.setBorder(B4);
box9.setBackground(Color.gray);
B5=new TitledBorder(new LineBorder(Color.black,2),"");
box10.setBorder(B5);
box10.setBackground(Color.gray);
player=new TitledBorder(new LineBorder(Color.black,5),"Player");
player.setTitleColor(Color.black);
Player.setBorder(player);
JPanel Hand=new JPanel();
JButton1=new JButton("Draw Hand");
JButton1.setActionCommand("Draw a Hand");
JButton1.addActionListener(new ActionListener()
{publicvoid actionPerformed(ActionEvent e)
{Object object=e.getSource();
if(e.getSource()==object)
{cardDeck.restoreDeck();
cardDeck.shuffle();
myHand.discardHand();
for (int i = 0; i < SIZE_OF_HAND; i++ )
{Card c = cardDeck.dealCard();
myHand.addCard( c );
handLbl[i].setIcon( c.getCardImage() );
handLbl[i].setText( c.toString() );
}
showBlackjackScore();
}
}
});
Hand.add(JButton1);
Hand.setBackground(Color.green);
cardsBottom.setBackground(Color.green);
Player.setBackground(Color.green);
Player.add(cardsBottom);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Messages=new JTextArea("-Messages-\n\n\n",10,42);
JScrollPane scroller=new JScrollPane(Messages);
Messages.setEditable(false);
Messages.setForeground(Color.white);
Messages.setBackground(Color.gray);
panel2.setBackground(Color.green);
panel2.add(scroller);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
JButton Exit=new JButton("Exit");
Exit.setToolTipText("Disconnect");
Hit=new JButton("Hit");
Hit.setToolTipText("Ask another card?");
Stand=new JButton("Stand");
Stand.setToolTipText("Satisfied with your card/s?");
JLabel l1=new JLabel("");
JLabel l2=new JLabel("");
JLabel l3=new JLabel("");
JLabel l4=new JLabel("");
JLabel l5=new JLabel(" ");
Exit.addActionListener(new ActionListener()
{publicvoid actionPerformed(ActionEvent e)
{System.out.println("Disconnected from BlackJack Thank you for Gambling!");
System.exit(0);
}
});
Hit.addActionListener(new ActionListener()
{publicvoid actionPerformed(ActionEvent e)
{Messages.append("Hit Me!!\n");}
});
Stand.addActionListener(new ActionListener()
{publicvoid actionPerformed(ActionEvent e)
{Messages.append("Stand\n");}
});
Flow.add(l1);
Flow.add(l2);
Flow.add(l3);
Flow.add(l4);
Flow.add(l5);
Flow.add(Exit);
Flow.add(Hit);
Flow.add(Stand);
Flow.setBackground(Color.green);
p.add(Flow);
//++++++++++++++++++++++++++++++++++++++++++++++++++++
container.add(panel1);
container.add(Opponent);
container.add(Player);
container.add(Hand);
container.add(panel2);
container.add(p);
}//end of Black Jack client constructor
publicvoid init()
{cardDeck =new Deck();
Iterator suitIterator = Suit.VALUES.iterator();
while ( suitIterator.hasNext() )
{Suit suit = (Suit) suitIterator.next();
Iterator rankIterator = Rank.VALUES.iterator();
while ( rankIterator.hasNext() )
{Rank rank = (Rank) rankIterator.next();
String imageFile = directory + Card.getFilename( suit, rank );
ImageIcon cardImage =new ImageIcon( getImage( getCodeBase(), imageFile ) );
Card card =new Card( suit, rank, cardImage );
cardDeck.addCard( card );
}
}
}//end of init
privatevoid showBlackjackScore()
{
int score = myHand.evaluateHand();
if( score == 21 )
{scoreLbl.setText( score +"!" );
scoreLbl.setForeground( Color.red );
}
else
{scoreLbl.setText("" + score );
scoreLbl.setForeground( Color.black );
}
}//end of showBlackjackScore
}//end of class Black Jack client

