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.OvalSprite;
05
06 /**
07 * Draws a simple bumble bee (sans stripes) in the center of the screen.
08 * Demonstrates how to use transformations (to rotate the oval wings),
09 * sprite outlines, and transparent colors.
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 Bee
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 the "game": create four sprites: body, head, left wing and
15 * right wing. Place the body in the center of the screen and position
16 * the other sprites accordingly (slightly above, to the left and to
17 * the right of the bee's body.
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 // Let the bee fly on a grassy background.
22 setBackground(getColor("green"));
23
24 OvalSprite beeBody =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.5, 0.7);
25 beeBody.setColor(getColor("Goldenrod"));
26 beeBody.setLocation(0.5, 0.6);
27 beeBody.setOutlineColor(getColor("black"));
28 beeBody.setOutlineThickness(0.01);
29 beeBody.showOutline();
30 addSprite(beeBody);
31
32 OvalSprite beeHead =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.35, 0.35);
33 beeHead.setColor(getColor("black"));
34 beeHead.setLocation(0.5, 0.18);
35 addSprite(beeHead);
36
37 OvalSprite leftWing =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.35, 0.7);
38 leftWing.setColor(getColor("Wheat", 128));
39 leftWing.setOutlineColor(getColor("black"));
40 leftWing.setOutlineThickness(0.01);
41 leftWing.showOutline();
42 leftWing.rotateDegrees(+adds two numbers together or concatenates Strings together20.0);
43 leftWing.setLocation(0.36, 0.6);
44 addSprite(leftWing);
45
46 OvalSprite rightWing =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(0.35, 0.7);
47 rightWing.setColor(getColor("Wheat", 128));
48 rightWing.setOutlineColor(getColor("black"));
49 rightWing.setOutlineThickness(0.01);
50 rightWing.showOutline();
51 rightWing.rotateDegrees(-20.0);
52 rightWing.setLocation(0.64, 0.6);
53 addSprite(rightWing);
54 }close braces end code blocks and must match an earlier open brace
55 }close braces end code blocks and must match an earlier open brace
56
57 //Uploaded on Mon Mar 29 21:40:42 EDT 2010
|
Download/View scg/ch03/Bee.java