View RSS Feed

Java AWT

Stroking and Filling Graphics Primitives

Rate this Entry
by , 03-06-2012 at 08:00 PM (603 Views)
In this post, discussion will be done regarding the outlines and color which are applicable to the graphics. Stroking as well as filling will also be discussed.

Fi
  • lling To paint with color gradient or solid color.
  • Stroking Outline of shape is drawn by applying color attribute, stroke width and line style.


Change paint attributes & stroke that are given in Graphics2D context. This is done before line styles are rendered or patterns are filled to the geometric primitives.

Geometric primitives are enriched along with stroking context and filling, by using these code lines.
Java Code:
// draw RoundRectangle2D.Double
final static float dash1[] = {10.0f};
    final static BasicStroke dashed =
        new BasicStroke(1.0f,
                        BasicStroke.CAP_BUTT,
                        BasicStroke.JOIN_MITER,
                        10.0f, dash1, 0.0f);
g2.setStroke(dashed);
g2.draw(new RoundRectangle2D.Double(x, y,
                                   rectWidth,
                                   rectHeight,
                                   10, 10));
// fill Ellipse2D.Double
redtowhite = new GradientPaint(0,0,color.RED,100, 0,color.WHITE);
g2.setPaint(redtowhite);
g2.fill (new Ellipse2D.Double(0, 0, 100, 50));

Submit "Stroking and Filling Graphics Primitives" to Facebook Submit "Stroking and Filling Graphics Primitives" to Digg Submit "Stroking and Filling Graphics Primitives" to del.icio.us Submit "Stroking and Filling Graphics Primitives" to StumbleUpon Submit "Stroking and Filling Graphics Primitives" to Google

Comments