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 java.awt.Color;
04
05 importimport means to make the classes and/or packages available in this program fang2.attributes.Location2D;
06 importimport means to make the classes and/or packages available in this program fang2.core.Game;
07 importimport means to make the classes and/or packages available in this program fang2.sprites.CompositeSprite;
08 importimport means to make the classes and/or packages available in this program fang2.sprites.RectangleSprite;
09 importimport means to make the classes and/or packages available in this program fang2.sprites.StringSprite;
10
11 /** A button classclass is a group of fields and methods used for making objects. Twice as wide as high with centered text message. */
12 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 EasyButton
13 extendsextends means to customize or extend the functionality of a class CompositeSprite {open braces start code blocks and must be matched with a close brace
14 /** the button at the bottom of the screen */
15 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) RectangleSprite button;
16
17 /** text displayed, centered, on the button */
18 privateprivate is used to restrict access to the current class only finalfinal means not changeable (often used for constants) StringSprite buttonMessage;
19
20 /**
21 * Construct newnew is used to create objects by calling the constructor button. Horizontal, FANGBlue with same color text.
22 */
23 publicpublic is used to indicate unrestricted access (any other class can have access) EasyButton() {open braces start code blocks and must be matched with a close brace
24 button =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1.0, 0.5);
25 addSprite(button);
26 buttonMessage =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite();
27 addSprite(buttonMessage);
28 }close braces end code blocks and must match an earlier open brace
29
30 /**
31 * Check ifif executes the next statement only if the condition in parenthesis evaluates to true the button has been pressed.
32 *
33 * @returnnull truetrue is the boolean value that is the opposite of false ifif executes the next statement only if the condition in parenthesis evaluates to true mouse clicked within the button, falsefalse is a value for the boolean type and means not true otherwise.
34 */
35 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false isPressed() {open braces start code blocks and must be matched with a close brace
36 // The current game may have a mouse click or not.
37 Location2D mouseClick =this assignment operator makes the left side equal to the right side
38 Game.getCurrentGame().getClick2D();
39 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
40 ifif executes the next statement only if the condition in parenthesis evaluates to true (intersects(mouseClick)) {open braces start code blocks and must be matched with a close brace
41 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
42 }close braces end code blocks and must match an earlier open brace
43 }close braces end code blocks and must match an earlier open brace
44 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
45 }close braces end code blocks and must match an earlier open brace
46
47 /**
48 * Set the color of the background rectangle
49 *
50 * @paramthis is the Javadoc tag for documenting the purpose of parameters color the color to set the rectangle to.
51 */
52 @Override
53 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setColor(Color color) {open braces start code blocks and must be matched with a close brace
54 button.setColor(color);
55 }close braces end code blocks and must match an earlier open brace
56
57 /**
58 * Set text message; resize to fit in one line
59 *
60 * @paramthis is the Javadoc tag for documenting the purpose of parameters message the newnew is used to create objects by calling the constructor message forfor is a looping structure for repeatedly executing a block of code the button to display
61 */
62 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setText(String message) {open braces start code blocks and must be matched with a close brace
63 buttonMessage.setText(message);
64 // adjust size of text message to fit on the button
65 buttonMessage.setWidth(0.75);
66 }close braces end code blocks and must match an earlier open brace
67
68 /**
69 * Set the color of the text on the button.
70 *
71 * @paramthis is the Javadoc tag for documenting the purpose of parameters color the color to set the text to
72 */
73 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setTextColor(Color color) {open braces start code blocks and must be matched with a close brace
74 buttonMessage.setColor(color);
75 }close braces end code blocks and must match an earlier open brace
76 }close braces end code blocks and must match an earlier open brace
77
78 //Uploaded on Mon Mar 29 21:41:39 EDT 2010
|
Download/View scg/ch05/EasyButton.java