/*
 *  Class: RectangleApplet
 *
 *  Author:  Alyce Brady
 *       Based on the RectangleApplet class in Chap 4 of Computing
 *             Concepts with Java Essentials by Cay Horstmann,
 *             but updated to used Rectangle2D.Double.
 *
 *  Creation date:  2 March 2003
 *
 */

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

/**
 *  This class provides a simple example of an applet.  It
 *  draws two rectangles and a line.
 *
 *  @author Alyce Brady (based on code by Cay Horstmann)
 */
public class RectangleApplet extends Applet
{
    /** Paints the contents of the applet.  Called by the browser or
     *  appletviewer whenever the window has to be redrawn.
     **/
    public void paint(Graphics g)
    {
        // We're going to use the Graphics2D package.
        Graphics2D g2 = (Graphics2D)g;

        // Construct a rectangle and draw it.
        Rectangle2D.Double rect = new Rectangle2D.Double(5, 10, 20, 30);
        g2.draw(rect);

        // Construct another rectangle and fill it.
        Rectangle2D.Double rect2 = new Rectangle2D.Double(20, 35, 20, 30);
        g2.setColor(Color.red);
        g2.fill(rect2);

        // Construct a line and draw it.
        Line2D.Double line = new Line2D.Double(35, 55, 50, 80);
        g2.setColor(Color.green);
        g2.draw(line);
    }
}
