The Java2D API provides advanced two-dimensional graphics capabilities for programmers who require detailed and complex graphical manipulations. The API includes features for processing line art, text and images in packages java.awt, java.awt.image, java.awt.color, java.awt.font. java.awt.geom, java.awt.print and java.awt.image.renderable.
Drawing with the Java2D API is accomplished by using an instance of class Graphics2D (package java.awt). Class Graphics2D is a sub-class of class Graphics. In fact, the actual object used to draw in every
paint method is a Graphics2D object, which can be passed to the paint() method and accessed using the super-class Graphics reference, that is, g. To access the Graphics2D capabilities, the Graphics reference passed to paint to a Graphics2D reference must be downcast. To access the additional capabilities of Graphics2D while working with the Graphics class, the Graphics reference (g) must be type-cast to a Graphics2D reference by passing paint Component into Graphics2D. The syntax of casting Graphics2D to Graphics is the following:
Graphics2D g2d = (Graphics2D ) g;