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

public class Shapes2DX1 extends JApplet {
	Font f1, f2;
	String s1, s2;

	public void init( ) {
		f1 = new Font( "TimesRoman", Font.PLAIN + Font.ITALIC, 8 );
		f2 = new Font( "Courier", Font.BOLD, 192 );
		s1 = "Steve";
		s2 = "Buell";
	}

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

		// using a large font draw a String with a buffered background
		BufferedImage buffImage1 = new BufferedImage( 20, 10, BufferedImage.TYPE_INT_RGB );
		// create a Graphics2D object gg1
		Graphics2D gg1 = buffImage1.createGraphics( );
		gg1.setColor( Color.black );	// draw in black
		gg1.fillRect( 0, 0, 20, 10 );		// draw a filled black rectangle
		gg1.setColor( Color.red );		// draw in red
		gg1.setFont( f1 );
		gg1.drawString( s1, 1, 9 );		// draw string in red

		// repeat for a second BufferedImage
		BufferedImage buffImage2 = new BufferedImage( 20, 10, BufferedImage.TYPE_INT_RGB );
		// create a Graphics2D object gg2
		Graphics2D gg2 = buffImage2.createGraphics( );
		gg2.setColor( Color.black );	// draw in black
		gg2.fillRect( 0, 0, 20, 10 );		// draw a filled black rectangle
		gg2.setColor( Color.yellow );	// draw in yellow
		gg2.setFont( f1 );			// when accidentally set to f2 (a size of 196) gave a near effect
		gg2.drawString( s2, 1, 9 );		// draw string in yellow

		// set the paint to a texture paint
		TexturePaint tp1 = new TexturePaint( buffImage1, new Rectangle( 20, 10 ) );  // rectangle is same size as buffered image -- not required
		TexturePaint tp2 = new TexturePaint( buffImage2, new Rectangle( 20, 10 ) );

		// draw name in big font
		g2d.setFont( f2 );
		g2d.setPaint( tp1 );
		g2d.drawString( s1, 40, 220 );
		g2d.setPaint( tp2 );
		g2d.drawString( s2, 40, 440 );

		// draw box around names
		Rectangle2D.Double box1;
		box1 = new Rectangle2D.Double( 5, 5, 690, 490 );
		g2d.setStroke( new BasicStroke( 30.0f ) );
		g2d.draw( box1 );
	}
}