Amanda's SnowPerson

The GP Version

First of all I know that any program I write needs an applet. Therefore I'm going to make an applet class. I don't want the applet class to contain anything except for the frame so i did that...

Then I made the frame, I know that this frame is only going to contain the snowperson's face so I wrote that...it just instantiated the snow person's face...but the frame that I extended takes a container as a parameter...so mine takes a parameter and when I call super I hand the container to my parent so it know who to make the calls on...also, the shapes in the snowFace take a container as well as the filledOval the snowFace extends...so they need to be passed the same container...

Finally I made all of the Face Parts...then I went through and compiled it and then i ran it and everything was upside down! I forgot that in graphics the y coordinate is backwards...

I fixed that and then everything was dandy...

If you have questions just mail me... Amanda.


Applet

package SnowPerson.SnowPersonGP;

/**
 *  Package SnowPerson.SnowPersonGP
 *  class Applet
 *
 *  Okay, so for this applet, I'm going to need to instantiate one
 *  thing again, because my applet should not  contain too many things.
 *  But, what the applet should instantiate, in most programs, is a
 *  frame that contains everything. So, here it is...
 *  author aks
 */

public class Applet extends
GP.Containers.Applet {

  /*It extends the GP.Containers.Applet class because that is the
    calls that the suns know how to work with.  It is just a nice
    environment.
  */

  private MyFrame _myFrame;
  /*that is the name of the SnowPerson frame that I'm going to make...*/

  public Applet() {
    super();

    /*to inherit all the properties of GP.Containers.Applet class...*/

    _myFrame = new MyFrame(this);
    /*The GP.Containers.Frame takes a container as a parameter
      so, because this extends the GP.Containers.Applet class it
      is a container I can pass in this applet, in order to do that
      I write the word this because in java that refers to the current
      class...
    */
    
  }//public Applet()

}//public class Applet extends...

SnowFace

package SnowPerson.SnowPersonGP; /** * Package SnowPerson.SnowPersonGP * class SnowFace * * This class Extends the GP.Graphics.Shape.FilledOval class... * Therefore it has methods like setColor and setPosition... * author aks */ public class SnowFace extends GP.Graphics.FilledOval { private double SIZE = 100; /*everything will be drawn upon this constant so that we only have to change one constant to change the entire face's size. */ private double POSITION = 200; /*this puts it smack dab in the center...*/ private SnowEye _rightEye; private SnowEye _leftEye; private Mouth _mouth; private Nose _nose; /*these are the components of the face*/ public SnowFace (GP.Container container) { super(container); this.SetSize(new GP.Attributes.Size(SIZE, SIZE)); this.SetPosition(new GP.Attributes.Position(POSITION, POSITION)); this.SetColor(new GP.Attributes.Colors.White()); /*that line puts the face right in the middle of the frame because the default size of a frame is 400, 400... */ _rightEye = new SnowEye(container, SIZE/4, (POSITION+(SIZE/4)), (POSITION - (SIZE/4))); _leftEye = new SnowEye(container, SIZE/4, (POSITION -(SIZE/4)), (POSITION - (SIZE/4))); _nose = new Nose(container,(SIZE/6), POSITION, POSITION); /*that puts the nose in the center of the face*/ _mouth = new Mouth(container,(SIZE/6), POSITION, POSITION +(SIZE/4)); }//public SnowFace(Container container) }//public class SnowFace extends FilledOval

MyFrame

package SnowPerson.SnowPersonGP; /** * Package SnowPerson.SnowPersonGP
* class MyFrame

* * This class is the frame it will instnatiate the face which will be * another class... it takes a container as a parameter... * author aks */ public class MyFrame extends GP.Containers.Frame { private SnowFace _face;//this refers to the face it will instantiate public MyFrame(GP.Container container) { super(container);//so that the parent receives the same container /*The frame that only takes one parameter in GP has a default size and shape...we don't need to alter it unless we want to. */ _face = new SnowFace(container); /*Instantiation of the SnowFace */ }//public MyFrame(Container container { }//public class MyFrame....


Mouth

package SnowPerson.SnowPersonGP; /** * Package SnowPerson.SnowPersonGP * class Mouth * This class is the mouth... pretty boring i think... * author aks */ public class Mouth extends GP.Graphics.FilledOval { public Mouth(GP.Container container, double size, double x, double y) { super(container); this.SetSize(new GP.Attributes.Size(size, size/4)); this.SetPosition(new GP.Attributes.Position(x, y)); } }

Nose

package SnowPerson.SnowPersonGP; /** * Package SnowPerson.SnowPersonGP * class Nose * This class is a square and it extends the GP.Graphics.FilledSquare * class...not very interesting but oh well... * author aks */ public class Nose extends GP.Graphics.FilledRectangle { public Nose (GP.Container container, double size, double x, double y) { super(container); this.SetSize(new GP.Attributes.Size(size, size)); this.SetPosition(new GP.Attributes.Position(x, y)); this.SetColor(new GP.Attributes.Colors.Black()); } }

SnowEye

package SnowPerson.SnowPersonGP; /** * Package SnowPerson.SnowPersonGP
* class SnowEye

* * This class is an eye for the snowman...it contains a smaller eye for * the pupil...it is a circle... * author aks */ public class SnowEye extends GP.Graphics.FilledCircle { public SnowEye(GP.Container container, double size, double x, double y) { super(container); this.SetColor(new GP.Attributes.Colors.Blue()); this.SetSize(new GP.Attributes.Size(size, size)); this.SetPosition(new GP.Attributes.Position(x, y)); GP.Graphics.FilledCircle pupil = new GP.Graphics.FilledCircle(container); pupil.SetPosition(new GP.Attributes.Position(x, y + (size/4))); pupil.SetColor(new GP.Attributes.Colors.Black()); pupil.SetSize(new GP.Attributes.Size((size/4), (size/4))); } }


Reactions