import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class Figures extends Applet
{
private Graphics g;
public void init ()
{
addMouseListener
(new DrawPictureListener ());
g = getGraphics
();
} // method init
// Inner class that draws the picture
when the user clicks the mouse.
class DrawPictureListener implements
MouseListener
{
public void
mouseClicked (MouseEvent e)
{
Picture picture = new Picture ();
picture.drawPicture (g);
} // method
mouseClicked
public void
mouseEntered (MouseEvent e) {}
public void
mouseExited (MouseEvent e) {}
public void
mousePressed (MouseEvent e) {}
public void
mouseReleased (MouseEvent e) {}
} // class DrawPictureListener
} // class Figures
class Picture
{
public void drawPicture (Graphics
g)
{
Circle circle;
Color color;
for (int count
= 0; count < 200; count += 10)
{
if (count % 20 == 0)
color = Color.red;
else
color = Color.blue;
circle = new Circle (color, 50, 50, count);
circle.drawCircle (g);
}
} // method drawPicture
} // class Picture
class Circle
{
private Color color;
private int x, y, diameter;
Circle (Color c, int xPosition, int
yPosition, int d)
{
color = c;
x = xPosition;
y = yPosition;
diameter =
d;
} // constructor
public void drawCircle (Graphics g)
{
g.setColor
(color);
g.drawOval
(x, y, diameter, diameter);
} // method drawCircle
} // class Circle