|
001 packagepackage is used to name the directory or folder a class is in scg.ch09;
002
003 importimport means to make the classes and/or packages available in this program java.awt.Color;
004
005 importimport means to make the classes and/or packages available in this program fang2.core.Game;
006 importimport means to make the classes and/or packages available in this program fang2.sprites.StringSprite;
007
008 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 MultiplicationTable
009 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
010 /** The number of columns of numbers in the table */
011 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer COLUMNS =this assignment operator makes the left side equal to the right side 10;
012
013 /** The number of rows of numbers in the table */
014 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer ROWS =this assignment operator makes the left side equal to the right side 6;
015
016 /** StringSprite +adds two numbers together or concatenates Strings together space between them */
017 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions SPACING =this assignment operator makes the left side equal to the right side 1.0 /
018 (1 +adds two numbers together or concatenates Strings together Math.max(ROWS, COLUMNS));
019
020 /** Scale of StringSprites (forfor is a looping structure for repeatedly executing a block of code leaving space) */
021 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions ACTUAL_SCALE =this assignment operator makes the left side equal to the right side SPACING - 0.02;
022
023 /** Color forfor is a looping structure for repeatedly executing a block of code entries labeling the table */
024 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) Color LABEL_COLOR =this assignment operator makes the left side equal to the right side getColor("misty rose");
025
026 /** Offset from edge to labels (on top or left) */
027 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions LABEL_OFFSET =this assignment operator makes the left side equal to the right side SPACING / 2.0;
028
029 /** Color forfor is a looping structure for repeatedly executing a block of code entries in the table */
030 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) Color TABLE_COLOR =this assignment operator makes the left side equal to the right side getColor("yellow green");
031
032 /** Offset to first row or column (top/left) */
033 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions TABLE_OFFSET =this assignment operator makes the left side equal to the right side LABEL_OFFSET +adds two numbers together or concatenates Strings together SPACING;
034
035 /**
036 * Setup all of the sprites.
037 */
038 @Override
039 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
040 labelRows();
041 labelColumns();
042 fillProductTable();
043 }close braces end code blocks and must match an earlier open brace
044
045 /**
046 * Fill in the multiplication table. row and column are the numbers
047 * being multiplied together in a given cell on the screen
048 */
049 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value fillProductTable() {open braces start code blocks and must be matched with a close brace
050 doubledouble is the type for numbers that can contain decimal fractions yOffset =this assignment operator makes the left side equal to the right side TABLE_OFFSET;
051 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
052 doubledouble is the type for numbers that can contain decimal fractions xOffset =this assignment operator makes the left side equal to the right side TABLE_OFFSET;
053 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
054 makeOneEntry(xOffset, yOffset, row * column, TABLE_COLOR);
055 xOffset +=this increases the variable on the left by the value on the right SPACING;
056 }close braces end code blocks and must match an earlier open brace
057 yOffset +=this increases the variable on the left by the value on the right SPACING;
058 }close braces end code blocks and must match an earlier open brace
059 }close braces end code blocks and must match an earlier open brace
060
061 /**
062 * Generate label sprites down the left side of screen forfor is a looping structure for repeatedly executing a block of code rows
063 */
064 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value labelColumns() {open braces start code blocks and must be matched with a close brace
065 doubledouble is the type for numbers that can contain decimal fractions yOffset =this assignment operator makes the left side equal to the right side LABEL_OFFSET;
066 doubledouble is the type for numbers that can contain decimal fractions xOffset =this assignment operator makes the left side equal to the right side TABLE_OFFSET;
067 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer column =this assignment operator makes the left side equal to the right side 0; column !=this is the not equals operator which evaluates to true if both sides are different COLUMNS; ++this is the increment operator, which increases the variable by 1column) {open braces start code blocks and must be matched with a close brace
068 makeOneEntry(xOffset, yOffset, column, LABEL_COLOR);
069 xOffset +=this increases the variable on the left by the value on the right SPACING;
070 }close braces end code blocks and must match an earlier open brace
071 }close braces end code blocks and must match an earlier open brace
072
073 /**
074 * Generate label sprites across top of screen forfor is a looping structure for repeatedly executing a block of code the columns
075 */
076 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value labelRows() {open braces start code blocks and must be matched with a close brace
077 doubledouble is the type for numbers that can contain decimal fractions yOffset =this assignment operator makes the left side equal to the right side TABLE_OFFSET;
078 doubledouble is the type for numbers that can contain decimal fractions xOffset =this assignment operator makes the left side equal to the right side LABEL_OFFSET;
079 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer row =this assignment operator makes the left side equal to the right side 0; row !=this is the not equals operator which evaluates to true if both sides are different ROWS; ++this is the increment operator, which increases the variable by 1row) {open braces start code blocks and must be matched with a close brace
080 makeOneEntry(xOffset, yOffset, row, LABEL_COLOR);
081 yOffset +=this increases the variable on the left by the value on the right SPACING;
082 }close braces end code blocks and must match an earlier open brace
083 }close braces end code blocks and must match an earlier open brace
084
085 /**
086 * Create one StringSprite in the table or labels. All StringSprites
087 * in the table are right justified (so units digits all aligned
088 * vertically). The size of the sprites is the ACTUAL_SCALE which
089 * should be smaller then the SCALE which is used forfor is a looping structure for repeatedly executing a block of code spacing.
090 *
091 * @paramnull x x-coordinate of the sprite on the screen
092 * @paramnull y y-coordinate of the sprite on the screen
093 * @paramnull value numeric value forfor is a looping structure for repeatedly executing a block of code the text of the sprite
094 * @paramnull color color to give the sprite
095 *
096 * @returnnull a reference to the newly created StringSprite
097 */
098 privateprivate is used to restrict access to the current class only StringSprite makeOneEntry(doubledouble is the type for numbers that can contain decimal fractions x, doubledouble is the type for numbers that can contain decimal fractions y, intint is the type for whole numbers and it is short for integer value,
099 Color color) {open braces start code blocks and must be matched with a close brace
100 StringSprite tableEntry =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite();
101 tableEntry.setScale(ACTUAL_SCALE);
102 tableEntry.setLocation(x, y);
103 tableEntry.setColor(color);
104 tableEntry.rightJustify();
105 tableEntry.setText(Integer.toString(value));
106 addSprite(tableEntry);
107 returnreturn means to provide the result of the method and/or cease execution of the method immediately tableEntry;
108 }close braces end code blocks and must match an earlier open brace
109 }close braces end code blocks and must match an earlier open brace
110
111 //Uploaded on Mon Mar 29 21:39:26 EDT 2010
|