draw Dashed Bounding Box - Java java.awt

Java examples for java.awt:Graphics2D

Description

draw Dashed Bounding Box

Demo Code


//package com.java2s;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

public class Main {
    public static void drawDashedBoundingBox(Color c, Graphics g, int x1,
            int y1, int x2, int y2) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(c);//w  w  w .  j a v  a2s  .  c o m
        final float dash[] = { 2.0f };
        final BasicStroke dashed = new BasicStroke(1.0f,
                BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash,
                0.0f);
        g2d.setStroke(dashed);
        g2d.draw(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1));
    }
}

Related Tutorials