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
06 /**
07 * A simple game demonstrating how to draw a red square on the screen
08 * and then rotate it to make it into a diamond.
09 */
10
11 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 Diamond
12 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
13 /**
14 * Setup all of the sprites appearing in the game. A diamond is a
15 * square rotated 45 degrees. This draws a single diamond in the
16 * center of the screen.
17 */
18 @Override
19 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
20 // make background white
21 setBackground(getColor("white"));
22
23 // create the diamond, set its color, position, and rotation
24 RectangleSprite diamond =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);
25 diamond.setColor(getColor("red"));
26 diamond.setLocation(0.5, 0.5);
27 diamond.rotateDegrees(45.0);
28 addSprite(diamond);
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:39:41 EDT 2010
|
Download/View scg/ch03/Diamond.java