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 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. Many of the code examples in this chapter can be used either in applications (which we'll see in Recipe 13.2) or in applets (discussed more in Chapter 18).



Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net