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 5 of 5

Thread: JButton not being recognized

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default JButton not being recognized

    Hello,

    I am having a problem with some code I am making. I am trying to make a game. Just started a few weeks back. Well, I have three JButtons, but for some reason one is throwing a error when I try to compile it. Here is the code below:

     
    JButton Hack=new JButton("Hack");
    Hack.addActionListener=(new ActionListener(){
          public void actionPerformed(ActionEvent e){
             System.out.println("Hello");
     
         }
     
     
      });

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: JButton not being recognized

    one is throwing a error
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JButton not being recognized

    error: cannot find symbol
    Hack.addActionListener=(new ActionListener(){
    ^
    symbol: variable addActionListener
    location: variable Hack of type JButton

    --- Update ---

    Oh, I see my error. It's the =

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: JButton not being recognized

    .addActionListener=
    addActionListener is a method, not a variable. Leave out the = that is trying to assign .addActionListener a value.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    AstralBoat (July 31st, 2019)

  6. #5
    Junior Member
    Join Date
    Jul 2019
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JButton not being recognized

    Thanks for the help man!

Similar Threads

  1. LWJGL Keyboard-Inputs aren't recognized
    By DoMyBest in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 10th, 2014, 04:26 PM
  2. [SOLVED] do while problem / symbol not recognized
    By Christian_Doucet in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 27th, 2014, 06:46 AM
  3. [SOLVED] Javac Not recognized?
    By Future_Programmer in forum Java Theory & Questions
    Replies: 4
    Last Post: June 12th, 2013, 06:04 AM
  4. WSDL Classes not recognized
    By jb1111 in forum Web Frameworks
    Replies: 0
    Last Post: March 20th, 2012, 08:37 PM
  5. IP Can't Recognized
    By Voipswitch1 in forum Java Networking
    Replies: 1
    Last Post: February 8th, 2012, 06:03 PM