by Deborah AdairThis trail introduces you to the Java 2D API and shows you how to display and print 2D graphics in your Java programs. With the Java 2D API, you can easily:
This is a draft! Please send comments and suggestions on this trail to firstname.lastname@example.org with the word "2D" in the subject.
- Draw lines of any thickness.
- Fill shapes with gradients and textures.
- Move, rotate, scale, and shear text and graphics.
- Composite overlapping text and graphics.
For example, using the Java 2D API, you could display complex charts and graphs that use different line and fill styles to distinguish sets of data:
The Java 2D API also enables you to store and manipulate image data--for example, you can easily perform image-filter operations such as blur and sharpen.
This trail covers the most common uses of the Java 2D APIs and briefly describes some of the more advanced features. For additional information about using the Java 2D APIs, see the Java 2D Programmer's Guide. The JavaTM Developer ConnectionSM has more information in Java 2D: A Tutorial on Styled Text. Additional sample programs illustrating the Java 2D API features are also available online.
The Java 2D APIs are closely integrated with the Abstract Windowing Toolkit (AWT). If you are not familiar with AWT, you might find it useful to review the AWT documentation, Creating a User Interface before reading this trail.
Overview of the Java 2D API introduces the key Java 2D concepts and describes the Java 2D rendering model.
Displaying Graphics with Graphics2D teaches you how to set up the
Graphics2Drendering context to use fancy stroke and fill styles, perform transformations, clip the drawing region, composite overlapping graphics, and specify rendering preferences.
Manipulating and Displaying Images describes how to implement double-buffering and perform image-filter operations with
Printing teaches you how to render 2D graphics to a printer and print complex documents.