Usage

Ellipses can be drawn in an applet by instancing the GeneralPath class (using a constructor from either the GeneralPath.Float or the GeneralPath.Double inner classes,) and then using the draw method of the java.awt.Graphics2D class.  A Ellipse can be filled use the fill method of the java.awt.Graphics2D class. 

Package

java.awt.geom

Parent Classes

java.awt.geom.RectangularShape

Common Public Constructors

GeneralPath.Double ()
Creates a GeneralPath with a size of (0, 0) at a location of (0, 0).
GeneralPath.Double (double X, double Y, double Width, double Height)
Creates a GeneralPath with a size of (Width, Height) at location (X, Y).
GeneralPath.Float ()
Creates a GeneralPath with a size of (0, 0) at a location of (0, 0).
GeneralPath.Float (float X, float Y, float Width, float Height)
Creates a GeneralPath with a size of (Width, Height) at location (X, Y).

Common Public Methods

contains (double Xp, double Yp)
Returns true iff the point (Xp, Yp) is within the Ellipse.
contains (double X, double Y, double Width, double Height)
Returns true iff the Ellipse (X, Y, Width, Height) is entirely within the Ellipse.
intersects (double X, double Y, double Width, double Height)
Returns true iff the Ellipse (X, Y, Width, Height) intersects the Ellipse.
setFrame (double X, double Y, double Width, double Height)
Sets the location and size of the Ellipse.

Arguments

Height
Vertical size of the Ellipse, in pixels
Width
Horizontal size of the Ellipse, in pixels
X
Horizontal position of upper left corner, in pixels
Y
Vertical position of upper left corner, in pixels
X1
Horizontal location of one end of the line, in pixels.
X2
Horizontal location of the other end of the line, in pixels.
Xp
Horizontal location of the point, in pixels.
Y1
Vertical location of one end of the line, in pixels.
Y2
Vertical location of the other end of the line, in pixels.
Yp
Vertical location of the point, in pixels.

Applet - GeneralPath1.class

Source Code - GeneralPath1.java

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

public class GeneralPath1 extends Applet {
  private java.awt.geom.GeneralPath Shape1;
  private java.awt.geom.GeneralPath Shape2;

  public GeneralPath1 () {
    Shape1 = new java.awt.geom.GeneralPath ();
    Shape2 = new java.awt.geom.GeneralPath ();
    Shape1.moveTo (50, 50);
    Shape1.lineTo (50, 150);
    Shape1.lineTo (200, 50);
    Shape1.lineTo (200, 150);
    Shape1.lineTo (50, 50);
    Shape1.moveTo (75, 50);
    Shape1.lineTo (175, 50);
    Shape1.moveTo (75, 150);
    Shape1.lineTo (175, 150);
    Shape2.moveTo (250, 50);
    Shape2.lineTo (250, 150);
    Shape2.lineTo (400, 50);
    Shape2.lineTo (400, 150);
    Shape2.lineTo (250, 50);
    Shape2.moveTo (275, 50);
    Shape2.lineTo (375, 50);
    Shape2.moveTo (275, 150);
    Shape2.lineTo (375, 150);
  }

  public void paint (Graphics g) {
    Graphics2D g2D;

    g2D = (Graphics2D) g;

    g2D.draw (Shape1);
    g2D.fill (Shape2);
  }

}
/*
<applet code=GeneralPath1 Width=450 height=200>
</applet>
*/

External Links

Sun Tutorial Stroking and Filling Graphics Primitives