Using Java 2D API
To use Java 2D, implement a paint(…) method and cast the Graphics argument to a Graphics2D object
The following example demonstrates how you could use the Java 2D API to draw a red rectangle
- The basic process for drawing the rectangle with Java 2D API is the same as with java.awt, except the usage of GeneralPath to define rectangle.
Graphics2D g2d = (Graphics2D) g;