Java Reference
In-Depth Information
When used in a pattern for the DecimalFormat method, most characters,
both numeric and alphabetic, are taken literally — that is, they are unchanged
during formatting. On the other hand, special characters, such as those listed in
Table 4-17, stand for other characters, strings, or classes of characters; they are
replaced with the appropriate value when the method is called.
Table 4-17
Special Characters Used in Patterns
SYMBOL
PATTERN LOCATION
MEANING
0
Number
Digit; zero shows as leading or trailing zero
#
Number
Digit; zero shows as absent
.
Number
Decimal separator or monetary decimal
separator
Number
Minus sign
2
,
Number
Grouping separator
E
Number
Separates mantissa and exponent in scientific
notation
;
Subpattern boundary
Separates positive and negative subpatterns
%
Prefix or suffix
Multiply by 100 and show as percentage
Coding the paint() Method
Recall that the paint() method draws text in the applet window and displays
graphics and color. Figure 4-60 shows the code for the paint() method used in
the CommissionApplet program. Line 123 retrieves the image, dollarSign.gif;
line 124 draws the stored image in the applet.
120
121
public void paint ( Graphics g )
122
{
123
dollarSign = getImage ( getDocumentBase () , "dollarSign.gif" ) ;
124
g.drawImage ( dollarSign,12,28, this ) ;
125
}
FIGURE 4-60
The following step enters the paint() method in the applet.
 
Search WWH ::




Custom Search