Lab Project 9 - Strings and Arrays




  1. The ScrollBars allow for values between 0 and 255, inclusive. The scrollbars are for Red, Green and Blue and are used with the objectdraw Color constructor: new Color(red, green, blue);

  2. The awt TextField class is used to allow for data entry. The java.awt.TextField objects automatically respond to the Enter (Return) key by performing the actionPerformed() method, which is an implementation of the ActionListener interface.

  3. You may use either Labels from java.awt or Text objects from objectdraw package to show the separate letters. Each letter will be displayed in its own Label or Text object.

  4. There will be examples of both the ArrayList class and Java arrays available from this page. Your instructor will tell you in class or by email if you are restricted to using one or the other approach to solving this problem. You could actually use and learn both approaches by storing the FilledRect objects in an ArrayList and by storing the Text objects in a regular Java array.

  5. You can use the characters ASCII value to determine the color and the height of the FilledRect graphic..... Here are a few excerpts from the Strings example that is linked to above here.
    P maps to 15     Note that P is the 15th letter after A
    A maps to 0                P has ASCII value 80
    N maps to 13               A has ASCII value 65
    T maps to 19
    H maps to 7      redAmount = 10 * ( (int) input.charAt(i) - 65 );
    E maps to 4
    R maps to 17     Color colorForRect = new Color( redAmount, 0, 255 );
    S maps to 18     Letter A would have redAmount of 0, B would have 10,
                            C would have redAmount of 20, ... Z would have 250
    
             input = input.toUpperCase();
             for (int i = 0; i < input.length(); i++)
             {
                 int charValue = (int) input.charAt(i) - 65;
                 System.out.println( input.charAt(i) + " maps to " +
                                      charValue );
             }
    
  6. The height of the FilledRect would be similar to the above. A would be the shortest and Z would be the tallest.