tailieunhanh - Lecture Object Oriented Programing - Chapter 12: Graphics and java 2D™

In this chapter you will learn: To understand graphics contexts and graphics objects; to manipulate colors; to manipulate fonts; to use methods of class Graphics to draw lines, rectangles, rectangles with rounded corners, three-dimensional rectangles, ovals, arcs and polygons; to use methods of class Graphics2D from the Java 2D API to draw lines, rectangles, rectangles with rounded corners, ellipses, arcs and general paths. | 12 Graphics and Java 2D™ One picture is worth ten thousand words. Chinese proverb Treat nature in terms of the cylinder, the sphere, the cone, all in perspective. Paul Cézanne Colors, like features, follow the changes of the emotions. Pablo Picasso Nothing ever becomes real till it is experienced—even a proverb is no proverb to you till your life has illustrated it. John Keats OBJECTIVES In this chapter you will learn: To understand graphics contexts and graphics objects. To manipulate colors. To manipulate fonts. To use methods of class Graphics to draw lines, rectangles, rectangles with rounded corners, three-dimensional rectangles, ovals, arcs and polygons. To use methods of class Graphics2D from the Java 2D API to draw lines, rectangles, rectangles with rounded corners, ellipses, arcs and general paths. To specify Paint and Stroke characteristics of shapes displayed with Graphics2D. Introduction Graphics Contexts and Graphics Objects Color Control | 12 Graphics and Java 2D™ One picture is worth ten thousand words. Chinese proverb Treat nature in terms of the cylinder, the sphere, the cone, all in perspective. Paul Cézanne Colors, like features, follow the changes of the emotions. Pablo Picasso Nothing ever becomes real till it is experienced—even a proverb is no proverb to you till your life has illustrated it. John Keats OBJECTIVES In this chapter you will learn: To understand graphics contexts and graphics objects. To manipulate colors. To manipulate fonts. To use methods of class Graphics to draw lines, rectangles, rectangles with rounded corners, three-dimensional rectangles, ovals, arcs and polygons. To use methods of class Graphics2D from the Java 2D API to draw lines, rectangles, rectangles with rounded corners, ellipses, arcs and general paths. To specify Paint and Stroke characteristics of shapes displayed with Graphics2D. Introduction Graphics Contexts and Graphics Objects Color Control Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing Polygons and Polylines Java 2D API Wrap-Up Introduction Java contains support for graphics that enable programmers to visually enhance applications Java contains many more sophisticated drawing capabilities as part of the Java 2D API Classes Color Font, FontMetrics Graphics2D Polygon BasicStroke GradientPaint, TexturePaint Java 2D shape classes Fig. | Classes and interfaces used in this chapter from Java’s original graphics capabilities and from the Java 2D API. [Note: Class Object appears here because it is the superclass of the Java class hierarchy.] Introduction Java coordinate system Upper-left corner of a GUI component has the coordinates (0, 0) Contains x-coordinate (horizontal coordinate) - horizontal distance moving right from the left of the screen Contains y-coordinate (vertical coordinate) - vertical distance moving down from the top of