Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Asking what I suspect to be a very basic question

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Asking what I suspect to be a very basic question

    I am trying to solve the problem on the bottom of the code, with the "cannot find symbol" error. Any help will be much appreciated!!
    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");
     
    }}}
    Last edited by helloworld922; May 23rd, 2010 at 11:38 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Asking what I suspect to be a very basic question

    You declared Deck as a local variable of the init() method, but you're trying to use it in the actionPerformed() method.

    Suggested fix:
    Move the declaration of the Deck variable out to be a field of the class rather than just a local variable, but keep it's initialization inside the init() method.

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Asking what I suspect to be a very basic question


  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Asking what I suspect to be a very basic question

    Cross-posted: Asking what I suspect to be a very basic question

Similar Threads

  1. Basic Animation
    By tabutcher in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 10:07 AM
  2. Basic Beginner Help
    By SRD in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2010, 04:27 PM
  3. Basic Java Program Help
    By roaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2009, 10:28 PM
  4. Some basic questions.
    By trips in forum Java Theory & Questions
    Replies: 5
    Last Post: July 21st, 2009, 02:15 AM
  5. How to link two classes in java to use it method
    By Sterzerkmode in forum Object Oriented Programming
    Replies: 3
    Last Post: May 13th, 2009, 06:52 AM