import javax.swing.*; // For JApplet import java.awt.*; // Abstract Windowing Tookit: graphics stuff public class Circles extends JApplet { // Draw an unfilled circle colored c centered at (x,y) with radius r // in graphics context g. Leave the current graphics color invariant. public static void drawCircle (Graphics g, Color c, int x, int y, int r) { Color savedColor = g.getColor(); g.setColor(c); g.drawOval(x + 1 - r, y + 1 - r, 2*r - 1, 2* r -1); // Be careful of fencepost errors! g.setColor(savedColor); } public void paint (Graphics g) { Dimension screenSize = getSize(); // Get the applet's size int x1 = screenSize.width/4; int y1 = screenSize.height/4; int x2 = 3*screenSize.width/4; int y2 = 3*screenSize.height/4; // Draws concentric red circles centered about (x1,y1) for (int i = 1; i <= 128; i = i + 10) { drawCircle(g, Color.red, x1, y1, i); } // Draws concentric red circles centered about (x1,y1). // These are close enough to exhibit Moire patterns. for (int i = 1; i <= 128; i = i + 2) { drawCircle(g, Color.red, x2, y1, i); } // Draws concentric red circles centered about (x1,y1). // These are close enough to give a solid circle. for (int i = 1; i <= 128; i++) { drawCircle(g, Color.red, x1, y2, i); } // Draws concentric circles centered about (x1,y1) // that vary in shade from red (small circles) to // blue (large circles). for (int i = 1; i <= 128; i++) { drawCircle(g, new Color (255 - (2*i - 1), 0, 2*i - 1), x2, y2, i); } } }