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 7440743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:53:58+00:00 2026-05-29T10:53:58+00:00

The code is below. Basically, I have an anonymous instance of a Cell class

  • 0

The code is below. Basically, I have an anonymous instance of a “Cell” class which is supposed to draw something to the screen. Within one of the methods that I’ve overridden (annotated), I call a method that exists only within the anonymous class (randomFireBubble, marked with comments). Here’s the issue: the method executes and runs (I’ve put in various print statements to test this), but it doesn’t draw anything to the screen! But that’s not even the problem. The problem is that if I replace the call to the method with the body of the method, it runs perfectly as intended.

In essence my problem is this: if I replace a call to a method with the body of the method, and everything runs fine, why can’t I just call the method? This is baffling me.

Edit: I should clarify that it doesn’t really matter what randomFireBubble does. The issue is that if I have the body of the method in place of its call, then it works, but if I call the method, then it doesn’t.

public static Cell Fire (int x, int y, Grid grid)
{
    return new Cell(x, y, grid)
    {

        @Override
        public void draw (int size, int x, int y, Graphics graphics)
        {
            super.draw(size, x, y, graphics);

            cellColor = fireColor(Math.random());

            randomFireBubble(graphics, size); // < -- Problem here
        }

        private void randomFireBubble (Graphics graphics, int size)
        {
            int x1 = (int) StaticCalculations.randomDoubleBetween(- x * 1.5, x * 1.5);
            int y1 = (int) StaticCalculations.randomDoubleBetween(- y * 1.5, y * 1.5);

            int width1 = (int) StaticCalculations.randomDoubleBetween(0, size * 1.5);

            graphics.setColor(fireColor(Math.random()));

            graphics.fillOval((x + 1) * size - size / 2 + x1, (y + 1) * size - size / 2 + y1, width1, width1);
        }

//This method is irrelevant, it works perfectly fine.
        private Color fireColor (double r)
        {
            if(r <= 0.33)
            {
                return Color.yellow;
            }
            else if(r <= 0.66)
            {
                return Color.orange;
            }
            else
            {
                return Color.red;
            }
        }
    };

}
  • 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-05-29T10:53:59+00:00Added an answer on May 29, 2026 at 10:53 am

    That’s because “x” and “y” are defined within “draw” but not within “randomFireBubble”. I don’t even know how this compiles for you. It probably doesn’t and you’ve missed it, or there’s a problem with the code you’ve pasted above.

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

Sidebar

Related Questions

Hi I have this code below which basically after 25 seconds of showing the
Code below is working well as long as I have class ClassSameAssembly in same
I have this perl code below, basically want to loop through these 2 files.
Basically in the code below, my final array does not seem to have the
Basically, the code below will generate divs which are then captured using the jquery
So, I have the code below which works fine when entered into Google's Rich
So basically, I have something like this: <h2 class=clickable>Hello</h2> And I want to make
I basically have two forms, one for Male and another for Female. The code
I have a code something below: function showHideOptions() { $(#template1, #template2, #template3, #template4).css(display,none); $(this).css(display,block);
I have a problem with the code below. Basically im implementing a polling mechanism,

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.