From ggc
|
01 packagepackage is used to name the directory or folder a class is in jam;
02
03 importimport means to make the classes and/or packages available in this program fang.*;
04 importimport means to make the classes and/or packages available in this program java.awt.*;
05 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
06
07 /**
08 * All about my game.
09 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
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 ButtonExample extendsextends means to customize or extend the functionality of a class Game
12 {open braces start code blocks and must be matched with a close brace
13 /**an oval*/
14 privateprivate is used to restrict access to the current class only OvalSprite oval;
15 /**button to make red*/
16 privateprivate is used to restrict access to the current class only ButtonSprite redButton;
17 /**button to make white*/
18 privateprivate is used to restrict access to the current class only ButtonSprite whiteButton;
19
20 /**sets up the game*/
21 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
22 {open braces start code blocks and must be matched with a close brace
23 makeSprites();
24 addSprites();
25 }close braces end code blocks and must match an earlier open brace
26
27 /**makes the sprites*/
28 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
29 {open braces start code blocks and must be matched with a close brace
30 redButton=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ButtonSprite("Make Red");
31 redButton.setSize(0.5);
32 redButton.setLocation(0.25, 0.8);
33 redButton.enable(thisthis means the current object (the implicit parameter));
34 redButton.addTimedAction(newnew is used to create objects by calling the constructor RedChanger());
35
36 whiteButton=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ButtonSprite("Make White");
37 whiteButton.setSize(0.5);
38 whiteButton.setLocation(0.75, 0.8);
39 whiteButton.enable(thisthis means the current object (the implicit parameter));
40 whiteButton.addTimedAction(newnew is used to create objects by calling the constructor WhiteChanger());
41
42 oval=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(0.5, 0.5);
43 oval.setLocation(0.5, 0.3);
44 oval.setColor(Palette.getColor("white"));
45 }close braces end code blocks and must match an earlier open brace
46
47 classclass is a group of fields and methods used for making objects RedChanger extendsextends means to customize or extend the functionality of a class TimedAction
48 {open braces start code blocks and must be matched with a close brace
49 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
50 {open braces start code blocks and must be matched with a close brace
51 oval.setColor(Palette.getColor("red"));
52 }close braces end code blocks and must match an earlier open brace
53 }close braces end code blocks and must match an earlier open brace
54
55 classclass is a group of fields and methods used for making objects WhiteChanger extendsextends means to customize or extend the functionality of a class TimedAction
56 {open braces start code blocks and must be matched with a close brace
57 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value act()
58 {open braces start code blocks and must be matched with a close brace
59 oval.setColor(Palette.getColor("white"));
60 }close braces end code blocks and must match an earlier open brace
61 }close braces end code blocks and must match an earlier open brace
62
63 /**adds the sprites to the screen*/
64 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
65 {open braces start code blocks and must be matched with a close brace
66 addSprite(redButton, whiteButton, oval);
67 }close braces end code blocks and must match an earlier open brace
68
69 }close braces end code blocks and must match an earlier open brace
|
Download/View jam/ButtonExample.java