Using the Font Class
Colors and fonts are represented in Java by the Color and Font classes in the java.awt package. With these classes, you can present text in different fonts and sizes and change the color of text and graphics. Fonts are created with the Font(String, int, int) constructor, which takes three arguments:
• The typeface of the font as either a generic name (“Dialog,” “DialogInput,” “Monospaced,” “SanSerif,” or “Serif”) or an actual font name (“Arial Black,” “Helvetica,” or “Courier New”)
• The style as one of three class variables: Font.BOLD, Font.ITALIC, or Font.PLAIN
• The size of the font in points
The following statement creates a 12-point italic Serif Font object:
Font current = new Font("Serif", Font.ITALIC, 12);
If you use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access