Java Reference
In-Depth Information
Display 18.23
Some Methods and Constants for the Class
Font
(part 2 of 2)
"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
.
TIP:
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.
Chapter Summary
•
You can define a window listener class by having it implement the
WindowListener
interface.
•
An icon is an object of the class
ImageIcon
and is created from a digital picture.
You can add icons to
JButton
s,
JLabel
s, and
JMenuItem
s.
•
You can use the class
JScrollPane
to add scroll bars to a text area.
•
You can draw figures such as lines, ovals, and rectangles using methods in the class
Graphics
.
•
You can use the method
setColor
to specify the color of each figure or text drawn
with the method of the class
Graphics
.
•
You can define your own colors using the class
Color
.
•
Colors are defined using the RGB (red/green/blue) system.
•
You can use the method
drawString
of the class
Graphics
to add text to a
JFrame
or
JPanel
.
•
You can use the method
setFont
to set the font, style modifiers, and point size for
text written with the
drawString
method of the
Graphics
class.