// Shapes2D.java
// Demonstrates some Java2D shapes
// APPLET CODE="Shapes2D" HEIGHT=500 WIDTH=700
import javax.swing.*;
// import java.awt.event.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

public class Shapes2D extends JApplet {
	public void paint( Graphics g ) {
		// create 2D by casting g to Graphics2D
		Graphics2D g2d = ( Graphics2D ) g;

		// draw 2D ellipse filled with a blue-yellow gradient
		GradientPaint by = new GradientPaint( 5, 130, Color.blue, 50, 50, Color.yellow, true );
		g2d.setPaint( by );

		Ellipse2D.Double ell1;
		ell1 = new Ellipse2D.Double( 5, 30, 165, 300 );
	
		g2d.fill( ell1 );

		// draw a red rectangle with a thick border
		// create a BasicStroke object
		BasicStroke fat = new BasicStroke( 10.0f );
		g2d.setStroke( fat );
		// change color to red
		g2d.setPaint( Color.red );
		// create the rectangle object
		Rectangle2D.Double rect = new Rectangle2D.Double( 180, 30, 80, 100 );
		// draw the rectangle
		g2d.draw( rect );

		// draw 2D rounded rectangle with a buffered background
		BufferedImage buffImage = new BufferedImage( 10, 10, BufferedImage.TYPE_INT_RGB );
		// create a Graphics2D object gg
		Graphics2D gg = buffImage.createGraphics( );
		gg.setColor( Color.yellow );	// draw in yellow
		gg.fillRect( 0, 0, 10, 10 );		// draw a filled yellow rectangle
		gg.setColor( Color.black );		// draw in black
		gg.drawRect( 1, 1, 6, 6 );		// draw a black rectangle
		gg.setColor ( Color.blue );		// draw in blue
		gg.fillRect( 1, 1, 3, 3 );		// draw a filled blue rectangle
		gg.setColor( Color.red );		// draw in red
		gg.fillRect( 4, 4, 3, 3 );		// draw a filled rectangle
		// set the paint to a texture paint
		TexturePaint tp = new TexturePaint( buffImage, new Rectangle( 10, 10 ) );  // rectangle is same size as buffered image -- not required  10, 10
		g2d.setPaint( tp );
		// draw the round rectangle
		g2d.fill( new RoundRectangle2D.Double( 280, 30, 150, 350, 50, 50 ) );

		// draw 2D pie-shaped arc in black
		g2d.setPaint( Color.black );
		BasicStroke mid;
		mid = new BasicStroke( 6.0f );
		g2d.setStroke( mid );
		Arc2D.Double pie;
		pie = new Arc2D.Double( 450, 30, 75, 100, 0, 270, Arc2D.PIE );
		g2d.draw( pie );
		
		// draw two 2D lines - one solid and one dashed
		g2d.setPaint( Color.green );
		g2d.draw( new Line2D.Double( 550, 30, 680, 250 ) );
		// set size of dashes
		float dashes[ ] = { 20, 5 };  // first element is the length of the dash???
		g2d.setPaint( Color.blue );
		g2d.setStroke( new BasicStroke( 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10, dashes, 0 ) );
		g2d.draw( new Line2D.Double( 680, 30, 550, 250 ) );
	}
}