Chapter 23. Working with Graphics

<feature><title></title>

WHAT YOU’LL LEARN IN THIS HOUR:

  • Setting the font and color of text

  • Setting up a container’s background color

  • Drawing lines, rectangles, and other shapes

  • Drawing GIF and JPEG graphics

  • Drawing filled and unfilled shapes

</feature>

During this hour, you learn how to turn Swing containers—the plain gray panels, applets, and frames that hold graphical user interface (GUI) components—into an artistic canvas on which you can draw fonts, colors, shapes, and graphics.

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 ...

Get Sams Teach Yourself Java™ in 24 Hours, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.