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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:00:44+00:00 2026-05-11T22:00:44+00:00

I have a task to draw a circle and then fill in with the

  • 0

I have a task to draw a circle and then fill in with the most amount of circles without touching the sides. I can draw the circle, and I can make loops to pack the circle in a hexagonal/honeycomb format, but can’t control whether they are inside or outside the circle.

I have used this: g.drawOval(50, 50, 300, 300); to specify my circle. Given I’m actually specifying a square as my boundaries I can’t actually determine where the circle boundaries are. So I’m basically packing the square full of circles rather than the circle full of circles.

Can some please point me in the right direction? I’m new to java so not sure if I have done this the complete wrong way. My code is below. I have another class for the frame and another with the main in it.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class DrawCircle extends JPanel
{
    private int width, height, diameter;
    public DrawFrame d;

    public DrawCircle()
    {
        width = 400;
        height = 400;
        diameter = 300;
    }


    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(Color.blue);
        g.drawOval(50, 50, 300, 300);

        for(int i=50; i<200; i=i+20)
        {
            for(int j=50; j<350; j=j+10)
            {
                g.drawOval(j, i, 10, 10);
            }
        }

        for(int i=60; i<200; i=i+20)
        {
            for(int j=55; j<350; j=j+10)
            {
                g.drawOval(j, i, 10, 10);
            }
        }

        for(int i=330; i>190; i=i-20)
        {
            for(int j=340; j>40; j=j-10)
            {
                g.drawOval(j, i, 10, 10);
            }
        }

        for(int i=340; i>190; i=i-20)
        {
            for(int j=345; j>40; j=j-10)
            {
                g.drawOval(j, i, 10, 10);
            }
        }




    }
}
  • 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-11T22:00:44+00:00Added an answer on May 11, 2026 at 10:00 pm

    All those magic numbers make me cringe a bit. You’re new to Java, and it’s homework, so I understand why you’re doing it, but I would not recommend it if you do much programming in the future.

    You need an algorithm or recipe for deciding when a small circle on the inside falls outside the big one you’re trying to pack. Think about the ways you might do this:

    1. If the distance between the center of the big circle and the small circle is is greater than the difference in their radii, the small circle will overlap the big circle or fall completely outside it.

    You can add this check to your code: Just before you draw the circle, perform this check. Only draw if that circle passes.

    Don’t worry about Java for a second; draw yourself a picture on a piece of paper, draw that enclosing and packed circle, and see if that statement is correct. Then think about any corner situations that it might not cover, just as a check.

    I’ll make two more recommendations. First, do this by hand without a computer once so you’ll see what the “right” answer might look like. Second, see if you can separate the calculation of the circles from the drawing part. It might make your job easier, because you can concentrate on one thing at a time. It’s called “decomposition”. You solve complex problems by breaking them up into smaller, more manageable pieces. In this case, it’s also called “model-view separation”. You might need to know that someday.

    Maybe another way to think about this problem would be to imagine a 2D arrangement of circles, packed in their closest arrangement, extending to infinity in both the x- and y-directions. Now take your enclosing circle, put it on top of the 2D arrangement, and eliminate all the circles that overlap the big circle. I don’t know if it’ll be optimal, but it’s easy to visualize.

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

Sidebar

Related Questions

I have task to write program allowing users to draw stars, which can differ
I have a task - draw smooth curve input: set of points (they added
i have task which takes a parameter and has three modes of results Example
I have task involving reading SAS .xpt files using .NET. For that I'm using
I am working on map kit and i have task to change location in
I am new this sharepoint development and i have task in hand to do
I have a task to automatically email a report of who is in a
I have a task that requires me to delete all folders in a directory
I have ad task manager working in another projec, but when I converted the
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end

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.