Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

10.9 Summary

Java 2D enables the artistic imagination of any programmer to produce high-quality, professional graphics. Java 2D opens the door to numerous possibilities; you can

  • Draw or fill any Shape. Simply call the Graphics2D's draw or fill methods with the shape as an argument.

  • Take advantage of the setPaint method in the Graphics2D class to paint shapes in solid colors (Color), gradient fills (GradientPaint), or with tiled images (TexturePaint).

  • Explore transparent shapes and change mixing rules for joining shapes. Numerous Porter-Duff mixing rules in the AlhpaComposite class define how shapes are combined with the background.

  • Break the "one pixel wide" pen boundary and create a BasicStroke to control the width of the pen, create dashing patterns, and define how line segments are joined.

  • Create an AffineTransform object and call setTransform on the Graphics2D object to translate, rotate, scale, and shear those shapes before drawing.

  • Control the quality of image through the RenderingHints. In addition, the RenderingHints can control antialiasing of colors at shape boundaries for a smoother, more appealing presentation.

Remember that Java 2D is a part of the Java Foundation Classes and only available with the Java 2 platform. Swing, a robust set of lightweight components, is also a fundamental component of the Java Foundation Classes. Swing is covered in Chapter 14 (Basic Swing) and Chapter 15 (Advanced Swing).

Drawing fancy shapes, text, and images is nice, but for a complete user interface, you need to be able to react to actions taken by the user, create other types of windows, and insert user interface controls such as buttons, textfields, and the like. These topics are discussed in the next three chapters.

  • + Share This
  • 🔖 Save To Your Account