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();
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);
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);
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);
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.
Now, I can see Mickey Mouse in my 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); } }