Register for EarthWeb's Million Dollar Sweepstakes!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


For text and graphic instances of Graphics2D, the class looks at the current Paint implementation. You set the Paint instance by calling Graphics2D.setPaint().Paint itself is an interface; Sun has provided GradientPaint and TexturePaint to enable you to implement special effects.

Instead of a Paint-based object, you can set a Color.PathsFill, in Listing 39.18, uses this approach. You’ll notice lines such as

g2.setColor(Color.blue);

and

g2.setColor(Color.red);

Whether you’ve provided a Paint object or a Color object, Graphics2D uses it to obtain a PaintContext—a specific mapping of colors and textures into device space—and is now ready to apply the colors.

Applying the Colors Graphics2D objects are drawn on a java.awt.Composite object. The Composite interface contains predefined rules to combine the source with colors that have already been drawn.


NOTE:  Sun provides one example of a Composite-based class: AlphaComposite. This class implements a set of blending and transparency rules based on T. Porter and T. Duff’s paper, “Compositing Digital Images,” SIGGRAPH 84, 253-259. Read the API documentation on AlphaComposite to see the essence of these rules.

Dealing with Compatibility Issues

Not only does Sun have to deal with a range of device compatibility, it also has had to ensure that changes in JDK 1.2 don’t break the Graphics API of JDK 1.1. To help your Graphics2D objects deal with the range of rendering environments they may encounter, use Graphics2D.setRenderingHints(). This method accepts hints that you may want to add to improve the performance and appearance of your graphics.

Suppose, for example, that you know that an image contains a number of diagonal lines that would benefit from antialiasing. You might specify ANTIALIASING_ON—at runtime, the environment and the device driver would negotiate whether to actually make the antialiasing pass. If you’ve specified RENDER_SPEED, the device driver may ignore the ANTIALIASING_ON directive entirely, but for RENDER_QUALITY, the driver may use the best antialiasing algorithm at its disposal, even though that algorithm may require extra time.

The hint list includes the following:

  ANTIALIASING ON and ANTIALIASING_OFF—Controls whether an extra step is applied to smooth jagged edges.
  RENDER_SPEED and RENDER_QUALITY—Controls whether the rendering algorithm should optimize for performance or appearance.

Notice the line in Listing 39.18 that sets these hints:

g2.setRenderingHints(Graphics2D.ANTIALIASING,
⇒Graphics2D.ANTIALIAS_ON);

Java Resources on the Web

The Java language is continually being upgraded. New packages and versions are being released at a rapid pace. Many of these new features will increase the power and ease of Java graphics and animation programming. Continue to increase your Java graphics and animation knowledge and programming skills by keeping up with the latest developments over the Web.

The most important Web site is the Java home page provided by JavaSoft—the Java development branch of the Sun Corporation. The Java home page is at http://java.sun.com/.

Use the Search feature at the top of the page (or go to http://java.sun.com/share/search.html) and enter terms such as “graphics” or “animation” to see the latest information. You can also keep informed about the latest Java developments and software release dates at this Web site and download the latest production-quality Java development software. (For access to beta releases of the software, join the Java Developer Connection—it’s free—at http://developer.javasoft.com/.)

While browsing the JavaSoft site, you’ll want to visit
http://java.sun.com/products/java-media/2D/samples/README.html—as the URL suggests, that page shows sample code using the features of the new JDK 1.2.

In addition to the JavaSoft site, you can find some excellent central Java news-gathering sources on the Web. These also include reviews, tutorials, and other useful information. The best of these includes JavaWorld at

http://www.javaworld.com/

For example, they have archives of articles on graphics at http://www.javaworld.com/javaworld/topicalindex/jw-ti-graphics.html. Go to http://www.javaworld.com/javaworld/topicalindex/jw-ti-animation.html for information on animation.

You can download sample programs and tutorials from the Java archive at Gamelan (http://www.gamelan.com/), the Java library of http://www.developer.com/. Their graphics information is at http://www.developer.com/directories/pages/dir.java.programming.graphics.html.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.