O'Reilly logo

Java Cookbook, 2nd Edition by Ian F Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Graphics and Sound

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 capability. The first printing API was put forward in 1.1, and it was promptly replaced in 1.2. Both printing APIs, fortunately, are based on use of Graphics objects, so drawing code did not have to change; only the details of getting the right kind of Graphics object changed in moving from 1.1 to 1.2. 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 ability to make a terrific variety of marks on paper. Since 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. In JDK 1.2, this was extended to support additional formats (including MIDI) and to be usable from within an application as well. Meanwhile, the Java Media Framework—standard extension javax.media—provides for playing (and eventually recording) audio, video, and possibly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required