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 importimport means to make the classes and/or packages available in this program fang2.sprites.StringSprite;
07
08 /** NewtonsApple pre-prototype */
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 NewtonsAppleSprites
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 // An OvalSprite field to name the apple
12 privateprivate is used to restrict access to the current class only OvalSprite apple;
13 // A RectangleSprite field to name newton
14 privateprivate is used to restrict access to the current class only RectangleSprite newton;
15
16 // First pass at defining the sprites for the game
17 @Override
18 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
19 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);
20 apple.setColor(getColor("red"));
21 apple.setLocation(0.50, 0.00);
22
23 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);
24 newton.setColor(getColor("green"));
25 newton.setLocation(0.50, 0.90);
26
27 addSprite(newton);
28 addSprite(apple);
29 }close braces end code blocks and must match an earlier open brace
30 }close braces end code blocks and must match an earlier open brace
31
32 //Uploaded on Mon Mar 29 21:41:50 EDT 2010
|
Download/View scg/ch04/NewtonsAppleSprites.java