Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-12-2008, 12:42 PM
Member
 
Join Date: Sep 2008
Posts: 6
GenkiSudo is on a distinguished road
Beginner Java graphics - filling concentric circles with color
Hello everyone.

I have to do an exercise in which I'm supposed to draw olympic circles and color them in olympic color.
I don't have a problem with drawing them (I drew them as concentric circles).
My problem is coloring them.

I have 3 classes:

1.OlympicRing - it draws the outer and the inner circle

2.OlympicComponent - extends JComponent, creates 5 OlympicRing objects with different positions and colors

3.OlympicRingViewer (main method that creates a frame and adds the olympic component to it)

Now, I tried filling the outer ring with olympic color and inner ring with frame background color (code is from OlympicRing class):
Code:
g2.draw(outerRing); g2.setColor(ringColor); g2.fill(outerRing); g2.draw(innerRing); g2.setColor(g2.getBackground()); g2.fill(innerRing);
This works with one ring. But if there's more of them and they intersect, their intersection areas get covered with background color.

Is there a way to give boundaries to the fill method ? Am I making any sense?
Any suggestions?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-12-2008, 03:54 PM
Senior Member
 
Join Date: Aug 2008
Posts: 178
Supamagier is on a distinguished road
Use fillArc(x, y, w, h, startAngle, arcAngle) or/and drawArc. Real pain in the ass though.
__________________
check out
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, 100% made by me.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-12-2008, 03:54 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
their intersection areas get covered with background color.
I would think that the last one drawn is the one you see. The earlier ones will be overwritten. So since you have set the color to be the background color for the last fill, that is the color it would be.
Would fillPolygon allow you to select the parts of your display to be filled?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-12-2008, 04:02 PM
Senior Member
 
Join Date: Aug 2008
Posts: 178
Supamagier is on a distinguished road
with fillPolygon you can give the exact coordinates so it could work, but drawing a circle with fillpolygon...? good luck.
__________________
check out
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, 100% made by me.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-13-2008, 01:07 PM
Member
 
Join Date: Sep 2008
Posts: 6
GenkiSudo is on a distinguished road
Thanks for the push in the right direction. While reading about drawArc I stumbled upon an easier solution.
Instead of drawing inner and outer circle, I just have to draw one circle with thicker stroke.
Here's the final code for the OlympicRing class, if anyone is interested.

Code:
public class OlympicRing { final static BasicStroke myStroke = new BasicStroke(8); private int xPosition; private int yPosition; private int width; private int height; private Color ringColor; public OlympicRing (int x, int y, Color c) { xPosition = x; yPosition = y; width = 92; height = 92; ringColor = c; } public void draw (Graphics2D g2) { Ellipse2D.Double ring = new Ellipse2D.Double (xPosition, yPosition, width, height); g2.setStroke(myStroke); g2.setColor(ringColor); g2.draw(ring); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Beginner needs help on Loop,Math-syntax on Graphics obdi New To Java 13 07-06-2008 11:11 AM
Circles (Loops) Zebra New To Java 1 05-29-2008 08:38 AM
[SOLVED] Need help with Java Vocab for final (Beginner vocab) Zebra New To Java 9 05-26-2008 06:30 AM
beginner to Java notwist New To Java 15 04-18-2008 11:41 AM
Problem in printing java graphics Mahendra Java 2D 0 01-23-2008 02:45 PM


All times are GMT +3. The time now is 10:25 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org