Java Reference
In-Depth Information
Chapter 12. Media: Graphics, Audio,
Video
Introduction
The
Graphics
class and the
Component
method
paint()
have survived virtually unchanged
since the early days of Java. Together they provide a basic but quite functional graphics cap-
ability. The first printing API was put forward in 1.1, and it was promptly replaced in 1.2,
and again in 1.4. These printing APIs, fortunately, are based on the
Graphics
object, so
drawing code did not have to change; only the details of getting the right kind of
Graphics
object changed. The 2D (two-dimensional graphics) package is also based on
Graphics
;
Graphics2D
is a subclass of
Graphics
.
To put the 2D graphics in perspective, think about the tremendous boost that the Adobe
PostScript language gave to desktop publishing and printing. PostScript is both a scripting
language and a
marking engine
: it has the capability to make a terrific variety of marks on
paper. Because Java is already a comprehensive programming language, the 2D API needed
only to add the marking engine. This it did very well, using several ideas imported from
PostScript via Adobe's participation in the early design.
Also present from the beginning was the
AudioClip
class, which represents a playable sound
file. This was soon extended to support additional formats (including MIDI) and to be usable
from within an application as well. Meanwhile, the Java Media Framework (extension
javax.media
) and the newer JavaFX framework provide for playing audio, video, and pos-
sibly other media with much greater control over the presentation. You'll see examples in
this chapter.
But first let's look at the
Graphics
class.