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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:10:12+00:00 2026-06-02T19:10:12+00:00

As the title says, I’m having trouble with my Java code when it comes

  • 0

As the title says, I’m having trouble with my Java code when it comes to finally drawing the counters on my abacus. the code compiles and runs but the counters are drawn starting from the first row instead of the top row. On top of this the counters do not stack in each column, one counter appears and moves up and down the column depending on which button is clicked which is correct but the counters should either be adding as I left click or subtracting as I right click.

I’ve spent a couple of hours on this and I’m sure it’s something silly but my brain has stopped working and I cant think of any solutions.

Anyway, here is my code.

AbacusPanel.java

public void paint(Graphics g)
{
    g.setColor(Color.gray);
    g.fillRect(0,0,getWidth(), getHeight());
    g.setColor(Color.black);

    Graphics2D g2 = (Graphics2D)g;
    // we'll use Graphics2D for it's "draw" method -
    // neater than the Graphics "drawRect" suppled
    // (which you could also use)

    for (int i = 0;i<numCols;i++)
    {
        for(int j = 0;j<numRows;j++)
        {
            g2.draw(getRect(i,j));
        }
    }

    for(int thisCol= 0; thisCol < numCols; thisCol++)
    {
        for(int thisRow = 0; thisRow < numRows; thisRow++)
        {
            for(int counters=0; counters<=myAbacus.getNumCounters(thisCol); counters++)
            {
                Rectangle r2 = getRect(thisCol,myAbacus.getNumCounters(thisCol));
                g2.setColor(Color.red);
                g2.fillOval(r2.x, r2.y, r2.width, r2.height);
            }
        }
    }

}

Hopefully someone out there can point me in the right direction and sorry if any of this isn’t formatted how you would like. This is my first question post and I have tried to make it easy on the eyes.

  • 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-02T19:10:14+00:00Added an answer on June 2, 2026 at 7:10 pm

    As per my comment:

    When you draw the placeholders for stones, you iterate over columns and then rows. But when when draw the counters, you only iterate over columns and not rows. Why not rows also? And shouldn’t the result of getNumCounters() take both column & row as inputs, since you’re trying to get the number of counters per position on the mancala board, right?

    In answer to your second question, I would have to believe that getNumCounters() would have to take both the row and column as inputs. Since you’ve got two rows on the mancala board, and the number of stones is dependent upon both the column and whether it is in the first or second row, it wouldn’t make sense otherwise.

    Also, a third thing to think about. In your rectangle, when you’re drawing your counters, it seems would need to vary the position where they are — it appears to me that each of your counters is going to stack on top of each other, so 20 counters will look no different than 1.

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

Sidebar

Related Questions

As title says, im having trouble with my junit tests passing for checking if
As title says, mock code to demostrate my problem Driver Class import java.io.*; public
Title says all. Sample code: ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object>
As the title says, I'm having two questions. Edit : To clarify, they don't
Well title says all I guess. I've tried to print_r($_SERVER) but my 'post-request' I
As the title says, the file loads correctly but the loading screen only flashes
The title says everything. What is the CSS code to put shadows in the
As title says i whant to change my variables in java from my jruby
As title says, how do I call a java class method from a jsp,
The title says everything, but just to be clear I'll add some extra words.

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.