From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch03;
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.RectangleSprite;
05 importimport means to make the classes and/or packages available in this program fang2.transformers.SpinTransformer;
06
07 /** A sample program spinning five concentric squares. */
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 SpinningTarget03
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 /**
11 * Add five concentric, alternating color squares to center of screen.
12 * Then add an {open braces start code blocks and must be matched with a close brace@link SpinTransformer}close braces end code blocks and must match an earlier open brace to all five (use one
13 * transformer on five sprites) to spin the image around.
14 */
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 setup() {open braces start code blocks and must be matched with a close brace
17 RectangleSprite five =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.5, 0.5);
18 five.setColor(getColor("gold"));
19 five.setLocation(0.5, 0.5);
20 addSprite(five);
21
22 RectangleSprite four =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.4, 0.4);
23 four.setColor(getColor("blue"));
24 four.setLocation(0.5, 0.5);
25 addSprite(four);
26
27 RectangleSprite three =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.3, 0.3);
28 three.setColor(getColor("gold"));
29 three.setLocation(0.5, 0.5);
30 addSprite(three);
31
32 RectangleSprite two =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.2, 0.2);
33 two.setColor(getColor("blue"));
34 two.setLocation(0.5, 0.5);
35 addSprite(two);
36
37 RectangleSprite one =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.1, 0.1);
38 one.setColor(getColor("gold"));
39 one.setLocation(0.5, 0.5);
40 addSprite(one);
41
42 // SpinTransformer takes degrees/second of spin
43 SpinTransformer spinner =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor SpinTransformer(90.0);
44 one.addTransformer(spinner);
45 two.addTransformer(spinner);
46 three.addTransformer(spinner);
47 four.addTransformer(spinner);
48 five.addTransformer(spinner);
49 }close braces end code blocks and must match an earlier open brace
50 }close braces end code blocks and must match an earlier open brace
51
52 //Uploaded on Mon Mar 29 21:41:58 EDT 2010
|
Download/View scg/ch03/SpinningTarget03.java