Java Draw Dashed Line drawDashedRect(Graphics g, int x, int y, int width, int height)

Here you can find the source of drawDashedRect(Graphics g, int x, int y, int width, int height)

Description

draw Dashed Rect

License

Open Source License

Declaration

public static void drawDashedRect(Graphics g, int x, int y, int width, int height) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics;

public class Main {
    public static void drawDashedRect(Graphics g, int x, int y, int width, int height) {
        int vx, vy;

        // draw upper and lower horizontal dashes
        for (vx = x; vx < (x + width); vx += 2) {
            g.fillRect(vx, y, 1, 1);//from  ww w .jav a 2  s  .c  o  m
            g.fillRect(vx, y + height - 1, 1, 1);
        }

        // draw left and right vertical dashes
        for (vy = y; vy < (y + height); vy += 2) {
            g.fillRect(x, vy, 1, 1);
            g.fillRect(x + width - 1, vy, 1, 1);
        }
    }
}

Related

  1. drawDashedLine(Graphics2D graphics, double x1, double y1, double x2, double y2)
  2. drawDashedRect(Graphics g, int x, int y, int width, int height)
  3. drawDashedRect(Graphics2D graphics, Rectangle2D rectangle)