Java Reference
In-Depth Information
Setting Horizontal and Vertical Coordinates
The horizontal and vertical coordinates required by the
drawString() method are measured in pixels. A pixel , or picture
element, is the basic unit of programmable color on a computer
display or in a computer image. Think of a pixel as a dot of light;
the dots grouped together form characters and images. The physi-
cal size of a pixel depends on the resolution of the computer
screen. For instance, if your screen resolution is 800 by 600 pixels,
a horizontal (X-axis) coordinate of 400 would display approxi-
mately halfway across the screen.
The drawString() method must use a String as its first argument. However,
the system date object, currentDate, in line 21 is not a String. The toString()
method can be used to convert currentDate to a String; the code takes the form
of the variable currrentDate, followed by a period, followed by toString(). The
code is inserted as the first argument of the drawString() method. The toString()
method has no arguments in this applet.
Perform the following step to enter three drawString() methods.
To Code the drawString() Methods
1. Replace lines 19, 20, and 21 in the TextPad coding window with the
code shown in lines 19, 20, and 21 of Figure 2-51 on page 95. Delete
the println() methods in lines 22 and 23. Leave line 22 blank.
The drawString() methods replace the println() methods in lines 19 through
21 (Figure 2-53). The horizontal and vertical coordinates following each
string of characters set the position of the output display and replace the
horizontal tab escape characters.
drawString()
methods
println()
methods
deleted
FIGURE 2-53
 
Search WWH ::




Custom Search