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.LineSprite;
06 importimport means to make the classes and/or packages available in this program fang2.sprites.OvalSprite;
07
08 // FANG Demonstration program: CompositeSprite
09 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 AxisSnowman
10 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
11 privateprivate is used to restrict access to the current class only CompositeSprite redSnowman;
12
13 // spin the snowman about 4 times a minute; see how everything
14 // moves relative to (0.0, 0.0) ON snowman; 24 degrees/second
15 @Override
16 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
17 redSnowman.rotateDegrees(24.0 * secondsSinceLastCall);
18 }close braces end code blocks and must match an earlier open brace
19
20 // add three circles to snowman, add snowman to scene
21 @Override
22 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
23 redSnowman =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor CompositeSprite();
24
25 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);
26 head.setColor(getColor("SCG Red"));
27 head.setLocation(0, -0.35);
28 redSnowman.addSprite(head);
29
30 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);
31 middle.setColor(getColor("SCG Red"));
32 middle.setLocation(0.0, 0.0);
33 redSnowman.addSprite(middle);
34
35 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);
36 bottom.setColor(getColor("SCG Red"));
37 bottom.setLocation(0, 0.45);
38 redSnowman.addSprite(bottom);
39
40 LineSprite yAxis =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LineSprite(0, -0.5, 0, 0.5);
41 yAxis.setColor(getColor("white"));
42 redSnowman.addSprite(yAxis);
43
44 LineSprite xAxis =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor LineSprite(-0.5, 0, 0.5, 0);
45 xAxis.setColor(getColor("white"));
46 redSnowman.addSprite(xAxis);
47
48 // snowman scaled and placed off center on screen
49 redSnowman.setLocation(0.67, 0.67);
50 redSnowman.setScale(0.50);
51 addSprite(redSnowman);
52 }close braces end code blocks and must match an earlier open brace
53 }close braces end code blocks and must match an earlier open brace
54
55 //Uploaded on Mon Mar 29 21:40:30 EDT 2010
|
Download/View scg/ch05/AxisSnowman.java