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 java.awt.geom.Rectangle2D;
04
05 importimport means to make the classes and/or packages available in this program fang2.core.Game;
06 importimport means to make the classes and/or packages available in this program fang2.core.Sprite;
07 importimport means to make the classes and/or packages available in this program fang2.sprites.CompositeSprite;
08 importimport means to make the classes and/or packages available in this program fang2.sprites.OvalSprite;
09
10 // FANG Demonstration program: CompositeSprite
11 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 SnowmanSprite
12 extendsextends means to customize or extend the functionality of a class CompositeSprite {open braces start code blocks and must be matched with a close brace
13 // add three circles to snowman, add snowman to scene
14 publicpublic is used to indicate unrestricted access (any other class can have access) SnowmanSprite() {open braces start code blocks and must be matched with a close brace
15 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);
16 head.setColor(Game.getColor("SCGRed"));
17 head.setLocation(0, -0.25);
18 addSprite(head);
19
20 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);
21 middle.setColor(Game.getColor("SCGRed"));
22 middle.setLocation(0.0, 0.0);
23 addSprite(middle);
24
25 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);
26 bottom.setColor(Game.getColor("SCGRed"));
27 bottom.setLocation(0, 0.35);
28 addSprite(bottom);
29 }close braces end code blocks and must match an earlier open brace
30
31 // spin the snowman about 4 times a minute; see how everything
32 // moves relative to (0.0, 0.0) ON snowman.
33 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
34 rotateDegrees(24.0 * secondsSinceLastCall);
35 }close braces end code blocks and must match an earlier open brace
36
37 @Override
38 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false intersects(Sprite sprite) {open braces start code blocks and must be matched with a close brace
39 Rectangle2D spriteBounds =this assignment operator makes the left side equal to the right side sprite.getBounds2D().Rectangle2D();
40 Rectangle2D bounds =this assignment operator makes the left side equal to the right side getBounds2D().Rectangle2D();
41 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truebounds.intersects(spriteBounds)) {open braces start code blocks and must be matched with a close brace
42 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
43 }close braces end code blocks and must match an earlier open brace
44 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
45 }close braces end code blocks and must match an earlier open brace
46 }close braces end code blocks and must match an earlier open brace
47
48 //Uploaded on Mon Mar 29 21:42:17 EDT 2010
|
Download/View scg/ch05/SnowmanSprite.java