import java.awt.*;
import javax.swing.*;

/**
 * Demonstrates basic drawing methods and the use of colour.
 * Your task is described in the document: Exercise 1.5-Snowman.doc
 *	
 * @author Lewis/Loftus/Cocking (modified by Ms Cianci & Mr. Emmell)
 */
public class Snowman extends JApplet
{
	/**
	 * Modifies the size of the applet and sets the background
	 * colour to cyan to represent the sky.
	 */
	public void init()
	{
		setSize(300, 220);
		
		Container c = getContentPane();
		c.setBackground(Color.CYAN);					// sky
	} // end init method
	
	/**
	 * Draws a snowman on the applet.
	 *
	 * @param page Used to draw on the applet.
	 */ 
	public void paint(Graphics page)
	{
		super.paint(page);
		
		// The location of EVERYTHING on the applet will
		// depend upon the following two CONSTANTS
		// If you change the initial value of these CONSTANTS
		// EVERYTHING should move together...you may want to
		// try this and see what happens - you can always
		// change the values back to 150 and 50 afterwards
		final int MID = 150;
		final int TOP = 50;
		
		page.setColor(Color.lightGray);
		page.fillRect(0, 175, 300, 50); 				// ground	
		
		page.setColor(Color.yellow);
		page.fillOval(-40, -40, 80, 80); 				// sun	
		
		page.setColor(Color.white);
		page.fillOval(MID-20, TOP, 40, 40);				// head
		page.fillOval(MID-35, TOP+35, 70, 50); 			// upper torso
		page.fillOval(MID-50, TOP+80, 100, 60);			// lower torso
		
		page.setColor(Color.black);
		page.fillOval(MID-10, TOP+10, 5, 5);			// left eye
		page.fillOval(MID+5, TOP+10, 5, 5);				// right eye
		
		page.drawArc(MID-10, TOP+20, 20, 10, 190, 160);	// smile
		
		page.drawLine(MID-25, TOP+60, MID-50, TOP+40);	// left arm
		page.drawLine(MID+25, TOP+60, MID+55, TOP+60);	// right arm
		
		page.drawLine(MID-20, TOP+5, MID+20, TOP+5);	// brim of hat
		page.fillRect(MID-15, TOP-20, 30, 25);			// top of hat
		
	} // end paint method
 } // end class
 

Comments are closed.