From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch08;
02
03 importimport means to make the classes and/or packages available in this program fang2.core.*;
04 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
05
06 /**
07 * Demonstrate how a Sprite classclass is a group of fields and methods used for making objects object prints out using
08 * System.out.println.
09 */
10 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 PrintASprite
11 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
12 /** The value to print out. */
13 privateprivate is used to restrict access to the current class only Sprite someField;
14
15 /**
16 * Creates a rectangle sprite forfor is a looping structure for repeatedly executing a block of code the field; print field value several
17 * times to show toString method
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 setup() {open braces start code blocks and must be matched with a close brace
21 System.out.println("someField = " +adds two numbers together or concatenates Strings together someField);
22 someField =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(0.25, 0.25);
23 System.out.println("someField = " +adds two numbers together or concatenates Strings together someField);
24 someField.setLocation(0.5, 0.5);
25 addSprite(someField);
26 System.out.println("someField:" +adds two numbers together or concatenates Strings together someField.getX() +adds two numbers together or concatenates Strings together ", " +adds two numbers together or concatenates Strings together
27 someField.getY() +adds two numbers together or concatenates Strings together " - " +adds two numbers together or concatenates Strings together someField.getWidth() +adds two numbers together or concatenates Strings together ", " +adds two numbers together or concatenates Strings together
28 someField.getHeight());
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:38:48 EDT 2010
|
Download/View scg/ch08/PrintASprite.java