Java Reference
In-Depth Information
You now have some tools to improve the looks of a Java program. You can draw with
lines, rectangles, ellipses, polygons, fonts, colors, and patterns onto a frame, a panel, and
other user interface components using Java2D.
Java2D uses the same two methods for each drawing operation—
draw()
and
fill()
.
Different objects are created using classes of the
java.awt.geom
package, and these are
used as arguments for the drawing methods of
Graphics2D
.
Tomorrow on Day 14, “Developing Swing Applications,” you'll learn how to create
applications that are launched from a web page using Java Web Start technology.
Q I am confused by what the uppercase “F” is referring to in source code today.
It is added to coordinates, as in the method
polly.moveTo(5F, 0F)
. Why is the
“F” used for these coordinates and not others, and why is a lowercase “f” used
elsewhere?
A
The F and f indicate that a number is a floating-point number rather than an inte-
ger, and uppercase and lowercase can be used interchangeably. If you don't use one
of them, the Java compiler assumes that the number is an
int
value. Many methods
and constructors in Java require floating-point arguments but can handle integers
because an integer can be converted to floating-point without changing its value.
For this reason, constructors like
Arc2D.Float()
can use arguments such as 10 and
180 instead of 10F and 180F.
Q The antialiasing section of today's chapter refers to a class called
RenderingHint.Key
. Why does this class have two names separated by a
period? What does that signify?
A
The use of two names to identify a class indicates that it is an inner class. The first
class name is the enclosing class, followed by a period and the name of the inner
class. In this case, the
Key
class is an inner class within the
RenderingHint
class.