scg/ch06/StringValues

From FANG

Jump to: navigation, search

01 package scg.ch06;
02 
03 import fang2.core.Game;
04 import fang2.sprites.StringSprite;
05 
06 /**
07  * Demonstrates String functions and String literals.
08  */
09 public class StringValues
10   extends Game {
11   /**
12    * Creates local Strings and then demonstrates some String methods in
13    * various labels created on the screen.
14    */
15   @Override
16   public void setup() {
17     final double STRING_HEIGHT = 0.04;// a named constant. Used to step
18                                       // strings down screen
19     double yPosition = STRING_HEIGHT;// represents the y position of
20                                      // the next string sprite
21     String userFirstName = "Claes";
22     String userLastName = "Bos-Ladd";
23     // concatenation
24     String userFullName = userFirstName + " " + userLastName;
25 
26     // Constructor takes a string and then the scale.
27     StringSprite msg1 = new StringSprite("userFirstName = " +
28         userFirstName);
29     msg1.setLineHeight(STRING_HEIGHT);
30     msg1.setLocation(0.5, yPosition);
31     yPosition = yPosition + STRING_HEIGHT;
32     addSprite(msg1);
33 
34     StringSprite msg2 = new StringSprite("userLastName = " +
35         userLastName);
36     msg2.setLineHeight(STRING_HEIGHT);
37     msg2.setLocation(0.5, yPosition);
38     yPosition = yPosition + STRING_HEIGHT;
39     addSprite(msg2);
40 
41     StringSprite msg3 = new StringSprite("userFullName = " +
42         userFullName);
43     msg3.setLineHeight(STRING_HEIGHT);
44     msg3.setLocation(0.5, yPosition);
45     yPosition = yPosition + STRING_HEIGHT;
46     addSprite(msg3);
47 
48     StringSprite msg4 = new StringSprite(
49         "userFullName.toLowerCase() = " + userFullName.toLowerCase());
50     msg4.setLineHeight(STRING_HEIGHT);
51     msg4.setLocation(0.5, yPosition);
52     yPosition = yPosition + STRING_HEIGHT;
53     addSprite(msg4);
54 
55     StringSprite msg5 = new StringSprite(
56         "userFullName.toUpperCase() = " + userFullName.toUpperCase());
57     msg5.setLineHeight(STRING_HEIGHT);
58     msg5.setLocation(0.5, yPosition);
59     yPosition = yPosition + STRING_HEIGHT;
60     addSprite(msg5);
61 
62     StringSprite msg6 = new StringSprite(
63         "userFullName.substring(6, 9) = " +
64         userFullName.substring(69));
65     msg6.setLineHeight(STRING_HEIGHT);
66     // "Claes Bos-Ladd" [6-9) = "Bos"
67     //  00000000001111
68     //  01234567890123
69     msg6.setLocation(0.5, yPosition);
70     yPosition = yPosition + STRING_HEIGHT;
71     addSprite(msg6);
72   }
73 }
74 
75 //Uploaded on Mon Mar 29 21:40:15 EDT 2010


Download/View scg/ch06/StringValues.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games