Results 1 to 5 of 5
- 09-12-2008, 10:42 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 6
- Rep Power
- 0
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):
This works with one ring. But if there's more of them and they intersect, their intersection areas get covered with background color.Java Code:g2.draw(outerRing); g2.setColor(ringColor); g2.fill(outerRing); g2.draw(innerRing); g2.setColor(g2.getBackground()); g2.fill(innerRing);
Is there a way to give boundaries to the fill method ? Am I making any sense?
Any suggestions?
- 09-12-2008, 01:54 PM #2
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
Use fillArc(x, y, w, h, startAngle, arcAngle) or/and drawArc. Real pain in the ass though.
I die a little on the inside...
Every time I get shot.
- 09-12-2008, 01:54 PM #3
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.their intersection areas get covered with background color.
Would fillPolygon allow you to select the parts of your display to be filled?
- 09-12-2008, 02:02 PM #4
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
with fillPolygon you can give the exact coordinates so it could work, but drawing a circle with fillpolygon...? good luck.
I die a little on the inside...
Every time I get shot.
- 09-13-2008, 11:07 AM #5
Member
- Join Date
- Sep 2008
- Posts
- 6
- Rep Power
- 0
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.
Java 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); } }
Similar Threads
-
[SOLVED] Beginner needs help on Loop,Math-syntax on Graphics
By obdi in forum New To JavaReplies: 13Last Post: 07-06-2008, 09:11 AM -
Circles (Loops)
By Zebra in forum New To JavaReplies: 1Last Post: 05-29-2008, 06:38 AM -
[SOLVED] Need help with Java Vocab for final (Beginner vocab)
By Zebra in forum New To JavaReplies: 9Last Post: 05-26-2008, 04:30 AM -
beginner to Java
By notwist in forum New To JavaReplies: 15Last Post: 04-18-2008, 09:41 AM -
Problem in printing java graphics
By Mahendra in forum Java 2DReplies: 0Last Post: 01-23-2008, 12:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks