
**strong text**What you are seeing in the screenshot are two sets of concentric circles. The centers of the circles are 100 pixels apart. The circles have a width of 5, and the diameter of a circle is 20 pixels larger than its next smallest one. Diameters range from 20 to 480 pixels.
Hint: You can change the width of the 'pen' used for drawing to 5 pixels with the line g2.setStroke(new BasicStroke(5)).
Hint: A circle is just an oval whose width and height are the same.
Make the program from this older code:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Flower extends JPanel {
public void paintComponent(Graphics g){
final int centerX = 300;
final int centerY = 300;
final int ovalWidth = 100;
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.black);
g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth);
g2.rotate(Math.toRadians(15),centerX,centerY);
g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth);
g2.rotate(Math.toRadians(15),centerX,centerY);
g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth);
g2.rotate(Math.toRadians(15),centerX,centerY);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Window"); //frame is the window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Flower panel = new Flower(); //panel is the graphics area where we can draw
frame.add(panel); //put the panel inside the window
frame.setSize(640,640); //set the window size to 640x640 pixels
frame.setVisible(true);
}
}
![alt text][1]
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.