From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch04;
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.OvalSprite;
05 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
06
07 /** NewtonsApple pre-prototype */
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 NewtonsAppleDropApple
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 // An OvalSprite field to name the apple
11 privateprivate is used to restrict access to the current class only OvalSprite apple;
12 // A RectangleSprite field to name newton
13 privateprivate is used to restrict access to the current class only RectangleSprite newton;
14
15 /**
16 * place the apple at random x-coord at top of screen.
17 */
18 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value dropApple() {open braces start code blocks and must be matched with a close brace
19 apple.setLocation(randomDouble(), 0.00);
20 }close braces end code blocks and must match an earlier open brace
21
22 // First pass at defining the sprites for the game
23 @Override
24 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
25 apple =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.10, 0.10);
26 apple.setColor(getColor("red"));
27 dropApple();
28
29 newton =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.10, 0.10);
30 newton.setColor(getColor("green"));
31 newton.setLocation(0.50, 0.90);
32
33 addSprite(newton);
34 addSprite(apple);
35 }close braces end code blocks and must match an earlier open brace
36 }close braces end code blocks and must match an earlier open brace
37
38 //Uploaded on Mon Mar 29 21:38:42 EDT 2010
|
Download/View scg/ch04/NewtonsAppleDropApple.java