Using the Font Class

Colors and fonts are represented in Java by the Color and Font classes, which both belong to the java.awt package. With these classes, you can present text in several different fonts and sizes, and change the colors of text, graphics, and other elements.

One of the principles of object-oriented programming is to make an object work for itself, and the Font and Color objects follow this rule. They store all the information that's needed to display a font or change a color, and they can handle other related tasks that are required.

There are three things you need to know about a font to display it:

  • The typeface of the font: Either a descriptive name (Dialog, DialogInput, Monospaced, SanSerif, or Serif) or an actual font name ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.