Java Reference
In-Depth Information
Display 18.23
Some Methods and Constants for the Class
Font
The class
Font
is in the
java.awt
package.
CONSTRUCTOR FOR THE CLASS
Font
public
Font(String fontName,
int
styleModifications,
int
size)
Constructor that creates a version of the
font named by
fontName
with the specified
styleModifications
and
size
.
CONSTANTS IN THE CLASS
Font
Font.BOLD
Specifies bold style.
Font.ITALIC
Specifies italic style.
Font.PLAIN
Specifies plain style—that is, not bold and not italic.
NAMES OF FONTS (These three are guaranteed by Java.
Your system will probably have others as well as these.)
"Monospaced"
See Display 18.22 for a sample.
"SansSerif"
See Display 18.22 for a sample.
"Serif"
See Display 18.22 for a sample.
METHOD THAT USES
Font
public abstract void
setFont(Font fontObject)
This method is in the class
Graphics
. Sets the current font of the calling
Graphics
object to
fontObject
.
Self-Test Exercises
19. Suppose
g
is an object of type
Graphics
. Write a line of code that will set the
font for
g
to Sans Serif bold of size 14 points.
20. Suppose
g
is an object of type
Graphics
. Write a line of code that will set the
font for
g
to Sans Serif bold and italic of size 14 points.