The completed applet is given below.
Here is the completed applet. Look over how the named values (constants and variables) were used in computing the values for X and Y.
import javax.swing.JApplet; import java.awt.*; // Assume that the drawing area is 300 by 150. // Draw ten red circles side-by-side across the drawing area. public class TenCircles extends JApplet { final int width = 300, height = 150; public void paint ( Graphics gr ) { gr.setColor( Color.red ); int count = 0 ; while ( count < 10 ) { int diameter = width/10; int X = count*diameter; // the left edge of each square int Y = height/2 - diameter/2; // the top edge of the squares gr.drawOval( X, Y, diameter, diameter ); count = count + 1; } } }
Here is what the applet does:
The arithmetic we used is a bit tedious. If you got lost, go back and review. Or just move on. Although arithmetic like this is typical of graphics programming it is not important that you work through every detail of this example.
Look at the statements inside of the loop body. Are there any that do exactly the same thing for each iteration of the loop?