Drawing Text

From Progzoo
Jump to: navigation, search
g.drawString("Andrew was here.",10,20)

will draw the string above and to the right of the point 10,20

Drawing a String


[Font] [Default] [Show] [Resize] [History] [Profile]

setFont to use a larger font

The phrase

g.getFont().deriveFont(20f);

will create a new font based on the current font, but size 20.

Drawing a String with a larger font


[Font] [Default] [Show] [Resize] [History] [Profile]

new Font to specify the font family and style and size

The phrase

new Font("Serif",0,20)

specifies that the Serif font should be used, 0 mean plain (not italic or bold), 20 is the size. For bold you could use:

new Font("Serif",Font.BOLD,20)

For bold italic you could use

new Font("Serif",Font.BOLD|Font.ITALIC,20)
Drawing a string using Serif font


[Font] [Default] [Show] [Resize] [History] [Profile]