0

I am supposed to add a polygon orange nose and a polygon black hat, as well as writing to his scarf but can't figure it out. this is what I have so far. i cant seem to figure our if i need to use the fillpolygon or what.

import java.applet.Applet;
import java.awt.*;

public class SnowMan  extends Applet
{

    public void paint (Graphics frame)
    {
        //  set up some constants
        final int MID = 150;    // middle of the snowman
        final int TOP = 50;     // top of the snowman

        //  need to set the background colors
        setBackground (Color.cyan);

        // color the ground
        frame.setColor (Color.lightGray);
        // the ground is a blue rectangle
        frame.fillRect (1, 175, 500, 150) ;



        //  draw three large snowballs to make up snowman
        frame.setColor (Color.white);

        // draw head
        frame.fillOval (MID - 20, TOP, 40, 40);
        // draw middle (upper torso)
        frame.fillOval (MID - 35, TOP + 35, 70, 50);
        // draw base (lower torso)
        frame.fillOval (MID - 50, TOP + 80, 100, 60);

        //  draw in features of snowman
        frame.setColor (Color.black);

        //  draw eyes
        // draw left eye
        frame.fillOval (MID - 10, TOP + 10, 5, 5);
        // draw right eye
        frame.fillOval (MID + 5, TOP + 10, 5, 5);

        //Draw Buttons
        frame.fillOval (MID -2, TOP + 50, 5, 5);
        frame.fillOval (MID -2, TOP + 60, 5, 5);
        frame.fillOval (MID -2, TOP + 70, 5, 5);


        //  draw arms
        // draw left arm
        frame.drawLine (MID - 25, TOP + 60, MID - 50, TOP + 40);
        // draw right arm
        frame.drawLine (MID + 25, TOP + 60, MID + 55, TOP + 60);

        //  draw hat
        // draw brim of hat
        frame.drawLine (MID - 20, TOP + 5, MID + 20, TOP + 5);

        frame.fillRect (MID - 20, TOP + 35, 40, 10);


        // draw top of hat
        frame.fillRect (MID - 15, TOP - 20, 30, 25);

        frame.setColor (Color.red);

        // draw mouth
        frame.drawArc (MID - 10, TOP + 20, 20, 10, 190, 160);


    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Possible duplicate of [Creating a snowman with jframe?](https://stackoverflow.com/questions/45446382/creating-a-snowman-with-jframe) – Lexi Aug 01 '17 at 20:04
  • 1
    1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/moving-to-a-plugin-free-web). 3) Why use AWT? .. – Andrew Thompson Aug 02 '17 at 04:24
  • 1
    .. See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. – Andrew Thompson Aug 02 '17 at 04:24

1 Answers1

0

just create a polygon and draw it

public void paint (Graphics frame)
{
    ...
    //three points form a nose
    int[] xs = new int[]{10, 0,10};
    int[] yx = new int[]{0, 10,10}; //uhm - ugly triangle 'carrot' nose

    //TODO: set color before drawing

    //create polygon from three points
    Polygon p = new Polygon(xs, ys, 3);

    //draw the polygon
    frame.fill(p);
}

you have to set the nose on the proper position, so you must adjust the xs and ys value...

Martin Frank
  • 3,445
  • 1
  • 27
  • 47