Stroking or Filling a Shape - Java 2D Graphics

Java examples for 2D Graphics:Shape

Description

Stroking or Filling a Shape

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;

    // Set pen color for stroked shape
    g2d.setColor(Color.red);

    // Stroke the shape
    g2d.draw(shape);


    // Set fill color for filled shape
    g2d.setColor(Color.blue);

    // Fill the shape
    g2d.fill(shape);
}

Related Tutorials