|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
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. Youll notice lines such as g2.setColor(Color.blue); and g2.setColor(Color.red); Whether youve provided a Paint object or a Color object, Graphics2D uses it to obtain a PaintContexta specific mapping of colors and textures into device spaceand 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.
Dealing with Compatibility IssuesNot only does Sun have to deal with a range of device compatibility, it also has had to ensure that changes in JDK 1.2 dont 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_ONat runtime, the environment and the device driver would negotiate whether to actually make the antialiasing pass. If youve 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:
Notice the line in Listing 39.18 that sets these hints: g2.setRenderingHints(Graphics2D.ANTIALIASING, ⇒Graphics2D.ANTIALIAS_ON); Java Resources on the WebThe 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 JavaSoftthe 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 Connectionits freeat http://developer.javasoft.com/.) While browsing the JavaSoft site, youll want to visit 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 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.
|
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. |