Fonts and Graphics
Fonts
Two classes that deal with fonts are Font and FontMetric
The easiest way to change a font for a component or when drawing graphics is to use
setFont.
setFont("Font name", font style, point size);
Example Fonts, styles and point sizes
Font name | Font style | Point size
|
---|
System | Font.BOLD | 12
|
---|
Helvetica | Font.ITALIC | 24
|
---|
TimesRoman | Font.PLAIN | 18
|
---|
FontMetrics
FontMetric class is used to get the "metric" of font. For example the size of a certain character in
pixels. The font name, the ascent/descent of a font. This class is only useful if you require
such information as you may if you are trying to center text of any font regardless of size. Otherwise
the information in this class is rather useless.
Graphics
The AWT includes a Graphics class that allows for drawing of primitives,
regions(filled or not), manipulation of fonts and colors. There are
classes for manipulating and drawing images, double-buffering, etc.
But the Graphics class is abstract and thus we can not just create an instance of it. So we must get a Graphics instance, how? paint(), update(), etc. methods have one. But instead of overriding your Container'
paint() method try to extend a Canvas to draw graphics rather
than manipulate a Panel or Frame.
[Advanced graphics material to be added]
[Q & A's]
Q: ?
A:
[Next]
[Prev]
[Home]
Nelson Yu
nelson@cs.ualberta.ca
Last modified: Dec 2 1995