Start Search Contents Index Links About
MyShapes.java
/*
 * Author: Havard Rast Blok
 * E-mail: 
 * Web   : www.rememberjava.com
 */

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

/*
 * Draws a cirle, polygon and rectangle using Graphics2D
 */
public class MyShapes extends JFrame
{
  Ellipse2D.Double circle;
  Polygon polygon;
  Rectangle rectangle;
  int xpoints[] {100150170160130};
  int ypoints[] {100,  80120150160};

  public MyShapes()
  {
    super("MyShapes");
    setDefaultCloseOperationJFrame.EXIT_ON_CLOSE );
    setSize(300300);

    //init shapes
    circle = new  Ellipse2D.Double50504040 );
    polygon = new Polygonxpoints, ypoints, xpoints.length );
    rectangle = new Rectangle2002005050 );

    show();
  }

  public void paintGraphics g )
  {
    //use Graphics2D
    Graphics2D g2d = (Graphics2D)g;

    //draw the objects based on the contained values
    g2d.fillcircle );
    g2d.fillpolygon );
    g2d.fillrectangle );

  }

  public static void main(String args[])
  {
    new MyShapes();
  }
}


site: Håvard Rast Blok
mail:
updated: 27 July 2007