#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Help me out please!


    Im pretty new to Java and got a question I just cant seem to solve.

    I have a code looking like: (obv alot more but u know what I mean)

    java Code:
     
     
     
    public class project1 extends JFrame implements ActionListener {
     
    public project1() {
     
    JLabel jlabel = new JLabel("Dice 1") ;
     
    }
     
    public void actionPerformed(ActionEvent e){
     
    jlabel.setText("Regular");
     
    }
     
    }


    This gives me the error "cannot find symbol".

    I hope u can help me out !
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,200
    Rep Power
    2012
    You have declared jlabel inside the constructor and is therefor only known inside that function.

    Declare it as a class/member varible to fix the error.

    Comments on this post

    • codeJ agrees
    • Arnokeh agrees : Thank you, solved my problem

IMN logo majestic logo threadwatch logo seochat tools logo