Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:23:21+00:00 2026-06-14T05:23:21+00:00

I am calling the enclosing class method inside inner class, but I get syntax

  • 0

I am calling the enclosing class method inside inner class, but I get syntax error. Here is the code:

public class Horizon
{
  ....
  public void checkWinner()
  {
    if(x[1]==1 && x[2]==1 && x[3]==1 || x[4]==1 && x[5]==1 && x[6]==1 || x[7]==1 && x[8]==1 && x[9]==1)
    {
      JOptionPane.showMessageDialog(null, "Congratulations!\n      Player 1 won!", "Congratulations",JOptionPane.OK_OPTION);
    }
  }
  private class HandlerClass implements MouseListener
  {
    public void mouseClicked(MouseEvent event)
    {

      if(event.getSource()==lb1)
      {
        if(j==1)
          x[1]=1;
        else
          x[1]=2;
        lb1.setIcon(icon);
      }
      public void mousePressed(MouseEvent event){}
      public void mouseEntered(MouseEvent event){}
      public void mouseReleased(MouseEvent event){}
      public void mouseExited(MouseEvent event){} // error here

      Horizon.this.checkWinner(); 

      if(i==9)
      {
        JOptionPane.showMessageDialog(null, "The game is a draw", "Draw", JOptionPane.OK_OPTION);
      }

    }
  }

}

The error goes away when remove the method call.

What is the reason for this error and how can I solve it?
Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:23:23+00:00Added an answer on June 14, 2026 at 5:23 am

    You have placed method declarations inside a method declaration. Just move all those declaration outside mouseClicked:

      private class HandlerClass implements MouseListener
      {
        public void mouseClicked(MouseEvent event)
        {
          if(event.getSource()==lb1)
          {
            if(j==1)
              x[1]=1;
            else
              x[1]=2;
            lb1.setIcon(icon);
          }
    
          Horizon.this.checkWinner(); 
    
          if(i==9)
          {
            JOptionPane.showMessageDialog(null, "The game is a draw", "Draw", JOptionPane.OK_OPTION);
          }
        }
    
        public void mousePressed(MouseEvent event){}
        public void mouseEntered(MouseEvent event){}
        public void mouseReleased(MouseEvent event){}
        public void mouseExited(MouseEvent event){} // error here
      }
    

    By the way, I hope you are using an IDE to develop Java code. If so, find out how to automatically reformat the code and use this feature regurarly. In Eclipse it ist Ctrl-Shift-F.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio
Consider the code: class UPDServer { //start listener public void start() { UdpClient listener
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
So here's the deal. I created a user defined class. It contains a method
import java.lang.reflect.*; import java.util.Arrays; class Test { class Inner { public <T> Inner(T arg)
I'm calling a webservice in viewDidLoad method of tableViewcontroller class and parsing the data
I'm calling a library method that writes to a stream. But I want to
Calling the WriteObject Method from a background thread is not possible! Is there a
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
I am getting XamlParseException when calling XamlReader.Load() in button1_Click(object sender, RoutedEventArgs e) the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.