Explanation of Solution
Loop is used to draw identical circles:
//Loop from 0 through number of circles
for (int i = 1; i <= 6; i++)
{
//Set the color to fill
gc.setColor(Color.BLUE);
//Draw oval
gc.fillOval(x, y, DIAMETER, DIAMETER);
//Set the color to fill
gc.setColor(Color.BLACK);
//Draw the stroke
gc.drawOval(x, y, DIAMETER, DIAMETER);
//Update the value of x
x += DIAMETER + GAP;
}
Explanation:
The above “for” loop is used to create six identical circles. For each iteration,
- The color “BLUE” is set using “setColor ()” method.
- An oval is drawn using “fillOval ()” method.
- The color “BLACK” is set using “setColor ()” method.
- A stroke is drawn using “drawOval ()” method.
- The value of “x” is updated.
Complete program:
The below program is used to create six identical circles using Java applet.
//Import required packages
import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.Color;
//Define the main class that extends application class
public class SelfTest26 extends JApplet
{
//Declare required constant variables
//Set the gap
public static final int GAP = 50;
//Set the value of diameter
public static final int DIAMETER = 50;
//Set the value of X_CENTER
public static final int X_CENTER = 100;
//Set the value of U_CENTER
public static final int Y_CENTER = 100;
�...
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education