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

  • Home
  • SEARCH
  • 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 6688293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:23:17+00:00 2026-05-26T05:23:17+00:00

So I have a class that I constructed with a loop. In the constructor

  • 0

So I have a class that I constructed with a loop. In the constructor I have two while loops which make “grid” of circles. It’s supposed to be a scarf for class but I’m calling it chainmail because that sounds cooler. Anyways we’re supposed to be able to change the color of the scarf with a different (client) class. I obviously need to add a mutator method to change the color. Luckily there is a mutator for this in objectdraw called setColor(). It works just fine, except when I try to add it to this class it only changes the last circle in the grid. I know why this happens, but I don’t know how to fix it. I’ve commented out the “typical” mutator we’ve been using in class.

EDIT: Sorry for the confusion guys… this is just the class, I have a client that calls a new ChainMail() and then does a .setColor() on it but it only changes the last framedoval instead of all of them. That’s the problem

import objectdraw.*;
import java.awt.*;

public class ChainMail {

  private FramedOval link;

  public ChainMail(int rows,int links,
                   Location p,Color rgb,
                   DrawingCanvas c) {

    double numRows = 0;

    // create the number of rows specified
    while (numRows < rows) {

      double numLinks = 0;

      // create the number of links specified
      while (numLinks < links) {
        link = new FramedOval(p,12,12,c);
        link.setColor(rgb);

        // update the position
        p.translate(8,0);
        numLinks++;
      }

      // move position back to front col and down one row
      p.translate(-8*links,8);
      numRows++;

    }

  }

  public ChainMail(int rows,int links,Location p,DrawingCanvas c) {
    this(rows,links,p,Color.BLACK,c);
  }

  /* this doesn't work, only changes last circle
   * public void setColor(Color c) {
   *   link.setColor(c);
   * }
   */

}
  • 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-26T05:23:17+00:00Added an answer on May 26, 2026 at 5:23 am

    If you move it to class (as shown in commented code) then from where do you call this function ? I think this is what making the difference. Suppose you are doing following :

    1. remove “link.setColor(rgb);” from inside the while loop
    2. Uncomment public void setColor(Color c) function
    3. Create instance of ChainMail (say myChainMail)
    4. Call myChainMail.setColor(c)

    This scenario will give the result which you have reported i.e. only last circled gets colored.
    There are 2 ways to solve the issue :

    1. First is what you are already doing
    2. Instead of “private FramedOval link;” create “private ArrayList linkList = new ArrayList; Now before while create link variable of type FramedOval. Then after you do link = new FramedOval(p,12,12,c); in while loop add this to above created ArrayList.
      Now in setColor method of your class iterate over all the items in arraylist and set color on those items
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class constructor that expects a reference to another class object to
I have a class that has several member classes as attributes. The constructor of
In Java, how can I have a Runnable class that, depending on its constructor,
I have a constructor (for an auto generated class) that has 255 paremeters. Using
So I have a base class with a constructor that takes (T V) .
Suppose I have a Generic abstract class that provides some default constructor functionality so
I'm working on someone's code and they have a constructor that uses: class qwerty
I have class that represents users. Users are divided into two groups with different
I have class that extend FragmentActivity in it I add fragment to layout as
I have class that looks like this: class A { public: class variables_map vm

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.