Lesson: Working with Graphics

You might not need to read this lesson at all.
Many programs get by with no custom graphics.
If they display images,
they do so using
icons in standard Swing components such as
labels and
buttons.
To display styled text,
perhaps with embedded images and components,
they use
text components.
To customize the edges of components,
they use
borders.

If you can't find a component
that paints what you need onscreen,
then read on.
This lesson teaches you how to display
text,
simple shapes,
and images,
using API that works in both JDK 1.1 and 1.2.
Our examples create custom components,
but you might also use this API when creating a custom border
or icon implementation.
This lesson finishes with information about animation.

Note:
If you're using only Java 2 (JDK 1.2, and not JDK 1.1)
then in addition to reading the relevant pages in this lesson,
you should read the
2D Graphics trail.
That trail describes the
JavaTM 2D Graphics API,
which provides much more functionality
than the graphics primitives described in this lesson.

Many programs perform animation,
whether it's the classic, cartoon-style animation of Duke waving
or simply moving static images across the screen.
This section tells you how to perform animation,
using a Timer object
to implement an animation loop.