Java Reference
In-Depth Information
FIGURE 12-73
The length of the data fields can vary, depending on the details for a given
stock, so aligning the output can be difficult. Recall that StringBuffer objects
provide methods to obtain the length of the string data and to obtain a substring
of the data, given a starting location and length. Defining a StringBuffer consist-
ing of 20 space characters, as is done on line 158, allows substrings of spaces for
various lengths to be used for aligning the report output. Subtracting the length
of a data field to display from the number of spaces available yields the number
of space characters needed to align the output as desired (lines 173 through
188). Displaying the first field and then calculating the length of the first and
second fields together allows the first field to be left-aligned and the next to be
right-aligned. Subsequent fields are right-aligned, as well. Because the data is too
long to fit on a single line within the textarea, it is placed on two lines, with the
second line indented under the first.
 
Search WWH ::




Custom Search