From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch05;
02
03 importimport means to make the classes and/or packages available in this program fang2.core.Game;
04 importimport means to make the classes and/or packages available in this program fang2.sprites.CompositeSprite;
05 importimport means to make the classes and/or packages available in this program fang2.sprites.OvalSprite;
06
07 // FANG Demonstration program: CompositeSprite
08 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Snowman
09 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
10 privateprivate is used to restrict access to the current class only CompositeSprite redSnowman;
11
12 // spin the snowman about 4 times a minute; see how everything
13 // moves relative to (0.0, 0.0) ON the snowman; 24 degrees/second
14 @Override
15 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance(doubledouble is the type for numbers that can contain decimal fractions secondsSinceLastCall) {open braces start code blocks and must be matched with a close brace
16 redSnowman.rotateDegrees(24.0 * secondsSinceLastCall);
17 }close braces end code blocks and must match an earlier open brace
18
19 // add three circles to snowman, add snowman to scene
20 @Override
21 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
22 redSnowman =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor CompositeSprite();
23
24 OvalSprite head =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.3, 0.3);
25 head.setColor(getColor("SCG Red"));
26 head.setLocation(0, -0.25);
27 redSnowman.addSprite(head);
28
29 OvalSprite middle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.4, 0.4);
30 middle.setColor(getColor("SCG Red"));
31 middle.setLocation(0.0, 0.0);
32 redSnowman.addSprite(middle);
33
34 OvalSprite bottom =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.5, 0.5);
35 bottom.setColor(getColor("SCG Red"));
36 bottom.setLocation(0, 0.35);
37 redSnowman.addSprite(bottom);
38
39 // snowman scaled and placed off center on screen
40 redSnowman.setLocation(0.67, 0.67);
41 redSnowman.setScale(0.50);
42 addSprite(redSnowman);
43 }close braces end code blocks and must match an earlier open brace
44 }close braces end code blocks and must match an earlier open brace
45
46 //Uploaded on Mon Mar 29 21:39:25 EDT 2010
|
Download/View scg/ch05/Snowman.java