// Shapes2DX4.java
// Demonstrates gradient paint coordinates
// APPLET CODE="Shapes2DX4" HEIGHT=500 WIDTH=700
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

public class Shapes2DX4 extends JApplet {
	int x1, y1, x2, y2;  // coordinates of the two colors

	public void init( ) {
		x1 = 0;
		y1 = 0;
		x2 = 700;
		y2 = 500;
	}

	public void paint( Graphics g ) {
		// create graphics object by casting g to Graphics2D
		Graphics2D g2d = ( Graphics2D ) g;

		// draw 2D rectangle filled with a blue-yellow gradient
		GradientPaint by = new GradientPaint( x1, y1, Color.blue, x2, y2, Color.yellow, false );
		g2d.setPaint( by );

		// create the rectangle object
		Rectangle2D.Double rect = new Rectangle2D.Double( 1, 1, 698, 498 );
		// draw the rectangle
		g2d.fill( rect );

		g2d.setPaint( Color.black );
		g2d.fillOval( x1 - 2, y1 - 2, 4, 4 );
		g2d.fillOval( x2 - 2, y2 - 2, 4, 4 );
	}
}