// Shapes2DX2.java
// Demos some Java2D gradient paints
// APPLET CODE="Shapes2DX2" HEIGHT=600 WIDTH=700
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

public class Shapes2DX2 extends JApplet {
	private int ballW, ballH;
	private int xPos, yPos;

	public void init( ) {
		ballW = 140;
		ballH = 140;
		xPos = 5;
		yPos = 30;
	}

	public void paint( Graphics g ) {
		// create 2D by down casting g to Graphics2D
		Graphics2D g2d = ( Graphics2D ) g;

		// create new gradient paints
		GradientPaint bluYel1 = new GradientPaint( 20, 20, Color.blue, 60, 60, Color.yellow, false );
		GradientPaint blkRed1 = new GradientPaint( 130, 5, Color.black, 100, 100, Color.red, true );
		GradientPaint bluYel2 = new GradientPaint( 80, 80, Color.blue, 20, 20, Color.yellow, true );
		GradientPaint blkRed2 = new GradientPaint( 5, 130, Color.black, 100, 100, Color.red, true );
		GradientPaint greenBlu1 = new GradientPaint( 1, 1, Color.green, 60, 60, Color.blue, true );

		// create new ellipses
		Ellipse2D.Double ell1;
		ell1 = new Ellipse2D.Double( xPos, yPos, ballW, ballH );
		Ellipse2D.Double ell2;
		ell2 = new Ellipse2D.Double( 2 * xPos + ballW, yPos, ballW, ballH );

		Ellipse2D.Double ell3;
		ell3 = new Ellipse2D.Double( xPos, 2 * yPos + ballH, ballW, ballH );
		Ellipse2D.Double ell4;
		ell4 = new Ellipse2D.Double( 2 * xPos + ballW, 2 * yPos + ballH, ballW, ballH );

		Ellipse2D.Double ell5;
		ell5 = new Ellipse2D.Double( xPos, 3 * yPos + 2 * ballH, ballW, ballH );
		Ellipse2D.Double ell6;
		ell6 = new Ellipse2D.Double( 2 * xPos + ballW, 3 * yPos + 2 * ballH, ballW, ballH );

		// draw the ellipses
		g2d.setPaint( bluYel1 );
		g2d.fill( ell1 );
		g2d.setPaint( blkRed1 );
		g2d.fill( ell2 );
		g2d.setPaint( bluYel2 );
		g2d.fill( ell3 );
		g2d.setPaint( blkRed2 );
		g2d.fill( ell4 );
		g2d.setPaint( greenBlu1 );
		g2d.fill( ell5 );
		g2d.setPaint( greenBlu1 );
		g2d.fill( ell6 );
	}
}