From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch06;
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.StringSprite;
05
06 /**
07 * Demonstrates String functions and String literals.
08 */
09 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 StringValues
10 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
11 /**
12 * Creates local Strings and then demonstrates some String methods in
13 * various labels created on the screen.
14 */
15 @Override
16 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
17 finalfinal means not changeable (often used for constants) doubledouble is the type for numbers that can contain decimal fractions STRING_HEIGHT =this assignment operator makes the left side equal to the right side 0.04;// a named constant. Used to step
18 // strings down screen
19 doubledouble is the type for numbers that can contain decimal fractions yPosition =this assignment operator makes the left side equal to the right side STRING_HEIGHT;// represents the y position of
20 // the next string sprite
21 String userFirstName =this assignment operator makes the left side equal to the right side "Claes";
22 String userLastName =this assignment operator makes the left side equal to the right side "Bos-Ladd";
23 // concatenation
24 String userFullName =this assignment operator makes the left side equal to the right side userFirstName +adds two numbers together or concatenates Strings together " " +adds two numbers together or concatenates Strings together userLastName;
25
26 // Constructor takes a string and then the scale.
27 StringSprite msg1 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("userFirstName = " +adds two numbers together or concatenates Strings together
28 userFirstName);
29 msg1.setLineHeight(STRING_HEIGHT);
30 msg1.setLocation(0.5, yPosition);
31 yPosition =this assignment operator makes the left side equal to the right side yPosition +adds two numbers together or concatenates Strings together STRING_HEIGHT;
32 addSprite(msg1);
33
34 StringSprite msg2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("userLastName = " +adds two numbers together or concatenates Strings together
35 userLastName);
36 msg2.setLineHeight(STRING_HEIGHT);
37 msg2.setLocation(0.5, yPosition);
38 yPosition =this assignment operator makes the left side equal to the right side yPosition +adds two numbers together or concatenates Strings together STRING_HEIGHT;
39 addSprite(msg2);
40
41 StringSprite msg3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("userFullName = " +adds two numbers together or concatenates Strings together
42 userFullName);
43 msg3.setLineHeight(STRING_HEIGHT);
44 msg3.setLocation(0.5, yPosition);
45 yPosition =this assignment operator makes the left side equal to the right side yPosition +adds two numbers together or concatenates Strings together STRING_HEIGHT;
46 addSprite(msg3);
47
48 StringSprite msg4 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite(
49 "userFullName.toLowerCase() = " +adds two numbers together or concatenates Strings together userFullName.toLowerCase());
50 msg4.setLineHeight(STRING_HEIGHT);
51 msg4.setLocation(0.5, yPosition);
52 yPosition =this assignment operator makes the left side equal to the right side yPosition +adds two numbers together or concatenates Strings together STRING_HEIGHT;
53 addSprite(msg4);
54
55 StringSprite msg5 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite(
56 "userFullName.toUpperCase() = " +adds two numbers together or concatenates Strings together userFullName.toUpperCase());
57 msg5.setLineHeight(STRING_HEIGHT);
58 msg5.setLocation(0.5, yPosition);
59 yPosition =this assignment operator makes the left side equal to the right side yPosition +adds two numbers together or concatenates Strings together STRING_HEIGHT;
60 addSprite(msg5);
61
62 StringSprite msg6 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite(
63 "userFullName.substring(6, 9) = " +adds two numbers together or concatenates Strings together
64 userFullName.substring(6, 9));
65 msg6.setLineHeight(STRING_HEIGHT);
66 // "Claes Bos-Ladd" [6-9) = "Bos"
67 // 00000000001111
68 // 01234567890123
69 msg6.setLocation(0.5, yPosition);
70 yPosition =this assignment operator makes the left side equal to the right side yPosition +adds two numbers together or concatenates Strings together STRING_HEIGHT;
71 addSprite(msg6);
72 }close braces end code blocks and must match an earlier open brace
73 }close braces end code blocks and must match an earlier open brace
74
75 //Uploaded on Mon Mar 29 21:40:15 EDT 2010
|
Download/View scg/ch06/StringValues.java