Description of the Problem
Write a program that draws a series of eight concentric circles. The circles should be separated by 10 pixels. Use the drawArc method.
Sample Output
Program Template
1 // Lab 5 Circles.java
2 // This program draws concentric circles
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6
7 public class Circles extends JFrame {
8
9 // constructor
10 public Circles()
11 {
12 super( "Circles" );
13 setSize( 300, 300 );
14 setVisible( true );
15 }
16
17 // draw eight circles separated by 10 pixels
18 public void paint( Graphics g )
19 {
20 super.paint( g );
21
22 // create 8 concentric circles
23
27 }
28
29 // execute application
30 public static void main( String args[] )
31 {
32 Circles application = new Circles();
33 application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
34 }
35
36 } // end class Circles
Follow-Up Question and Activity
Using method fillArc, modify the program so that when the variable topLeft is at 0, 20, 40 and so on, the circles would be filled with color cyan; otherwise, fill them with color gray
Source Code:
package week5.practice;
//Lab 5 Circles.java // This program draws concentric circles import java.awt.*; import java.awt.event.*;
import javax.swing.*;
public class Cirlces extends JFrame {
// constructor public Cirlces() { super( "Circles" ); setSize( 300, 300 ); setVisible( true ); }
// draw eight circles separated by 10 pixels public void paint( Graphics g ) { super.paint( g ); // create 8 concentric circles for ( int topLeft = 0; topLeft < 80; topLeft += 10 ) { int y = 160 - ( topLeft * 2 ); // setting colors for each circle if( topLeft== 0) g.setColor(Color.CYAN); if( topLeft== 10) g.setColor(Color.GRAY);