Step 1: Drawing Mickey

For this example, I want to draw a silhouette of the famous Disney character Mickey Mouse any where within my Applet and at any size.   It is usually a good idea to simplify the problem at hand and solve an easier version.  Once that is solved, we can change parts of the code to get closer and closer to the solution of the original problem.  This keeps the problem from being overwhelming, and allows us to test and debug small changes all along the way.  To start on this problem, I will settle for being able to draw Mickey's silhouette only in the center of the Applet at a specific size. Once I can do that, I will generalize my code to solve the bigger problem. But I have to start somewhere!  

Create Head and Ear Ovals

Looking at Mickey, I should be able to use three filled ovals to represent his silhouette --- a large one for the head, and two smaller ones for the ears. To do this in Java, I first declare and create each:

   GP.Shapes.Oval face = new GP.Shapes.Oval();
   GP.Shapes.Oval leftEar = new GP.Shapes.Oval();
   GP.Shapes.Oval rightEar = new GP.Shapes.Oval();

Determine Position and Size of Head

Now I need to position and size the head.  I want it centered in the applet, which means the center is at coordinates (200, 200), and I'll pick a size of 200 for both the width and height. For each attribute, we will follow the pattern of declare the object, create the object, and then use the object.

   GP.Attributes.Dimension size = new GP.Attributes.Dimension(200, 200);
   face.SetSize(size);
   GP.Attributes.Coordinate center = new GP.Attributes.Coordinate(200, 200);
   face.SetPosition(center);

Determine Position and Size of Ears

Positioning and sizing the ears is a harder problem because they need to look right in relation to the head.  After some trial and error (many compilations and viewings in my browser), I worked out some coordinates and size for the ears. The most important thing to me was that I get the proportions reasonably correct and that the ears just touch the side of the head. 

In this case, note that we can save a little typing by not declaring each attribute first.  Instead, we will reuse the names declared above, but let them stand for a different object when needed. So in this case, we will simply create a new object and then use it. 

   size = new GP.Attributes.Dimension(120, 120);
   leftEar.SetSize(size);
   rightEar.SetSize(size);
   center = new GP.Attributes.Coordinate(90, 90);
   leftEar.SetPosition(center);
   center = new GP.Attributes.Coordinate(310, 90);
   rightEar.SetPosition(center);

Color Shapes

Finally, we color all the shapes black by declaring and creating a color object, and setting the color of the shapes.

   GP.Attributes.Color color = new GP.Attributes.Colors.Black();
   face.SetColor(color);
   leftEar.SetColor(color);
   rightEar.SetColor(color);

Final Code

Putting all the pieces of code above together within the applet, we get the following code that creates a Mickey Mouse silhouette in the center of the applet.

public class Applet extends GP.Containers.Applet
{
    public Applet ()
    {
	// create Mickey parts
	GP.Shapes.Oval face = new GP.Shapes.Oval();
	GP.Shapes.Oval leftEar = new GP.Shapes.Oval();
	GP.Shapes.Oval rightEar = new GP.Shapes.Oval();

	// set position of Mickey parts
	GP.Attributes.Coordinate center = new GP.Attributes.Coordinate(200, 200);
	face.SetPosition(center);
	center = new GP.Attributes.Coordinate(90, 90);
	leftEar.SetPosition(center);
	center = new GP.Attributes.Coordinate(310, 90);
	rightEar.SetPosition(center);

	// ears should be same size, face larger
	GP.Attributes.Dimension size = new GP.Attributes.Dimension(200, 200);
	face.SetSize(size);
	size = new GP.Attributes.Dimension(120, 120);
	leftEar.SetSize(size);
	rightEar.SetSize(size);

	// all parts are the same color
	GP.Attributes.Color color = new GP.Attributes.Colors.Black();
	face.SetColor(color);
	leftEar.SetColor(color);
	rightEar.SetColor(color);
    }
}
Now, I can see Mickey Mouse in my applet! 
Comments?