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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:00:19+00:00 2026-05-16T02:00:19+00:00

Could any body diagnose the problem I am facing? As you run the demo

  • 0

Could any body diagnose the problem I am facing?
As you run the demo you can see the middle part left blank, I need to fill the entire area..

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class FillDemo
{
    public static void main(String aths[])
    {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel pnl = new PolygonDemo();
        pnl.setSize(100, 200);
        f.getContentPane().add(pnl);
        f.setSize(400,280);
        f.setLocation(200,200);
        f.setVisible(true); 
    }
}

class PolygonDemo extends JPanel
{
    public PolygonDemo()
    {
        setBackground(Color.white);
    }

    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        Polygon p=new Polygon();

        p.addPoint(100,0);
        p.addPoint(100,100);
        p.addPoint(0,100);
        p.addPoint(0,0);

        p.addPoint(80,0);
        p.addPoint(80,20);
        p.addPoint(40,20);
        p.addPoint(40,40);
        p.addPoint(80,40);
        p.addPoint(80,100);
        p.addPoint(20,100);
        p.addPoint(20,80);
        p.addPoint(60,80);
        p.addPoint(60,60);
        p.addPoint(20,60);
        p.addPoint(20,0);
        p.addPoint(0,0);

        g2.setColor(Color.BLACK);
        g2.draw(p);
        g2.setColor(new Color(120,250,100));
        g2.fillPolygon(p);
        //g2.fillPolygon(p.xpoints,p.ypoints,p.npoints);

    }

}

Many thanks in advance

  • 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-16T02:00:19+00:00Added an answer on May 16, 2026 at 2:00 am

    Your polygon intersects with itself. The fillPolygon method can not clearly decide which point is in and which is out. From the fillPolygon javadoc:

    The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.

    Perhaps you can split your polygon into three single ones.

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

Sidebar

Related Questions

Could any body offer me any reason about that? If we do it like
could any body tell how to use Jquery calendar date time picker.
Could any body clarify these two expression for me ? What are cons and
Can any body tell me where xcode organizer saves the list of devices attached
Could any body explain, when to use TempData ViewBag ViewData I have a requirement,
Can any body help me in knowing how to pass a parameter from a
could any body explain what I should modify, how after hiding the image, still
Could any body give a short example for binding a value from list array
I don't knwo whether my desig itself wrong or what. but could any body
Any body could help me please! I want to use GDataXML but when I

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.