Results 1 to 9 of 9
  1. #1
    khaimaitien is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default how to fill a closed region with color in java

    I am running into a problem when I do a project in my class. I need to fill a closed region with color ( this is a function of paint in window OS ). Hope anyone can help me.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: how to fill a closed region with color in java

    Welcome to our forum. If you need help, please give us more information that would allow us to help you. Please show us what you've tried and tell us how it's not working, and ask about any specific concepts that you're unclear on. It would help if you also told us what graphics and GUI library you're using.

  3. #3
    khaimaitien is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: how to fill a closed region with color in java

    Our project is to make an application that looks like the paint in Window. We are looking for a solution to the filling a closed region with a chosen color. The problem is that a closed region doesn't have a definite shape ( such as polygon, Oval, ... ), it has an arbitrary shape. Until now, we haven't had any ideas about solving this problem. I hope someone can help me :(

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: how to fill a closed region with color in java

    You still haven't told us anything about what library you're using, is it Swing, AWT, SWT, Android, etc... Come on. If you're going to ask for help, at least make it possible for us to help you.

  5. #5
    khaimaitien is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: how to fill a closed region with color in java

    I use Swing (Java) to implement it and the closed region lies on the Jpanel. the problem is that if the closed region is a definite shape such as a rectangle, we can make use of fillrect() - a method of Graphics. A closed region has any form as long as It is closed.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: how to fill a closed region with color in java

    Would the fillPolygon() method work?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    khaimaitien is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: how to fill a closed region with color in java

    I don't think so, because a circle (forr example) is a closed region but not a poygon

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: how to fill a closed region with color in java

    Quote Originally Posted by khaimaitien View Post
    I use Swing (Java) to implement it and the closed region lies on the Jpanel. the problem is that if the closed region is a definite shape such as a rectangle, we can make use of fillrect() - a method of Graphics. A closed region has any form as long as It is closed.
    It sounds to me that the problem is as much about defining as filling these arbitrary closed shapes you are talking about.

    Java provides the Shape interface which has an associated notion of "insideness". It is quite possible your shapes could be implemented as instances of Shape. In that case Graphics2D provides a method for filling them.

    Have a read of 2D Graphics in Oracle's Tutorial. It discusses the Shape interface, the builtin classes that implement it and the associated Area class which allows you to build complex shapes out of simple ones. (by union, insection, difference etc).

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: how to fill a closed region with color in java

    And if you can't find a suitable implementation of Shape, check out Flood fill - Wikipedia, the free encyclopedia

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. java.sql.SQLException: Closed Connection
    By sunjavaboy in forum JDBC
    Replies: 4
    Last Post: 03-21-2012, 02:38 PM
  2. How to fill color on triangle
    By cassysumandak in forum New To Java
    Replies: 6
    Last Post: 04-15-2011, 01:25 AM
  3. Urgent Help -- Closed Java Clipboard
    By Nimrod in forum Advanced Java
    Replies: 6
    Last Post: 03-31-2010, 12:43 PM
  4. Replies: 1
    Last Post: 01-31-2010, 04:17 AM
  5. Change color of a region
    By sky in forum AWT / Swing
    Replies: 5
    Last Post: 11-24-2009, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •