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.attributes.Location2D;
04 importimport means to make the classes and/or packages available in this program fang2.core.Game;
05 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
06
07 /**
08 * ColoredRectangles demonstrates how to use local variables. The classclass is a group of fields and methods used for making objects
09 * has no fields and no setup method. In advance, it checks forfor is a looping structure for repeatedly executing a block of code a mouse
10 * click and ifif executes the next statement only if the condition in parenthesis evaluates to true there is one, it creates a newnew is used to create objects by calling the constructor, randomly sized and
11 * randomly colored rectangle centered where the mouse was clicked.
12 */
13 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 ColoredRectangles
14 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
15 /**
16 * Check forfor is a looping structure for repeatedly executing a block of code a mouse click; ifif executes the next statement only if the condition in parenthesis evaluates to true one is clicked, make a random
17 * rectangle.
18 */
19 @Override
20 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
21 Location2D mouseClick;
22 mouseClick =this assignment operator makes the left side equal to the right side getClick2D();
23
24 ifif executes the next statement only if the condition in parenthesis evaluates to true (mouseClick !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) {open braces start code blocks and must be matched with a close brace// any click at all?
25 RectangleSprite rectangle;
26 rectangle =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(randomDouble(), randomDouble());
27 rectangle.setColor(randomColor());
28 rectangle.setLocation(mouseClick);
29 addSprite(rectangle);
30 }close braces end code blocks and must match an earlier open brace
31 // Is rectangle in scope?
32 }close braces end code blocks and must match an earlier open brace
33 }close braces end code blocks and must match an earlier open brace
34
35 //Uploaded on Mon Mar 29 21:39:05 EDT 2010
|
Download/View scg/ch05/ColoredRectangles.java