Java 2D Examples


 
Clipping
Clipping.java displays two JComponents. One that clips a circle and the other that clips a rectangle.
 
ClosePath
ClosePath.java displays two JComponents. One that draws a triangle by closing a path and the other that does not. Notice that if a path is not closed, the default line caps are used.
 
Composite
Compositing.java demonstrates the various compositing operators with user defined transparency (Alpha Channel).
 
Curves
This interesting example defined in Curves.java demonstrates the difference between quadriatic and cubic curves. The user can change each curve/s control points in real time to see how they effect the path.
 
Line Caps
Caps.java uses several JComponents to display the available line caps. Note that all except the butt cap will extend beyond the end of the line.
 
Line Joins
Joins.java uses several JComponents to display the available line joins.
 
Strokes
This interesting example defined in Stroking.java demonstrates how to change the properties of a drawn line, including the dashing. Dashing is defined by a comma delimted list and a phase. The list indicates how many pixels to draw and skip. For example 10,4,5 will draw 10, skip 4, draw 5 and repeat. The phase is a number from 0-1 that indicates how far into the sequence to begin.
 
Winding Rules
Winding.java demonstrates how the two winding rules are interpreted in two common situations where a path is contained inside another path.