# Coloring The Nested Ellipses/Circles

• June 7th, 2013, 03:25 AM
Galea
Coloring The Nested Ellipses/Circles
Hey all,

I am learning Java Swing for 2 days and trying to do some simple codes for better learning.

I have three(can be more) nested elllipse. I want to fill the gaps between the ellipses with different colors. However, have little coordinate problem. That piece of code can properly draws 3 circles (or whatever number you want). I just want to fill the gaps between those nested circles with different colors. How to use fill method and how to give it correct coordinate parameters to do that job?
``` protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D obj = (Graphics2D)g; obj.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);   int maxRadius = Math.min(getWidth(), getHeight()); //int alpha = 255; //int range = 255 - 32; ignore those lines.   obj.setStroke(new BasicStroke(0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));   for(int i = 1; i< 4; i++){ // That code draws nested 3 circles.   float progress = (float) i / (float)4; // it increases the radiance of the ellipses step by step. //alpha = 255 - Math.round(range * progress); //Color color = new Color(0, 0, 0, alpha);     int radius = Math.round(maxRadius * progress);     int x = (getWidth() - radius) / 2; int y = (getHeight() - radius) / 2; obj.setColor(Color.BLACK); obj.draw(new Ellipse2D.Float(x, y , radius, radius)); //obj.fill(new Ellipse2D.Float(x, y, radius,radius ));     }   obj.dispose(); }```