Java Draw 3D Rectangle draw3DRect(Graphics g, int x, int y, int width, int height, boolean raise, int thickness)

Here you can find the source of draw3DRect(Graphics g, int x, int y, int width, int height, boolean raise, int thickness)

Description

Draw a 3D rectangle just like the draw3DRect() method of the AWT Graphics class but with the addition of a thickness parameter.

License

Open Source License

Parameter

Parameter Description
g Graphics context
x horizontal location of top left of 3DRect
y vertical location of top left of 3DRect
width Width of 3DRect in pixels
height Height of 3DRect in pixels.
raise true is 3DRect raises upward, false if 3DRect is to appear inset.
thickness The thickness of the 3D border.

Declaration

public static void draw3DRect(Graphics g, int x, int y, int width, int height, boolean raise, int thickness) 

Method Source Code

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

import java.awt.Graphics;

public class Main {
    /**//w w  w.j  a  v  a 2 s .  co  m
     * Draw a 3D rectangle just like the draw3DRect() method
     * of the AWT Graphics class but with the addition of a
     * thickness parameter.
     * @param g Graphics context
     * @param x horizontal location of top left of 3DRect
     * @param y vertical location of top left of 3DRect
     * @param width Width of 3DRect in pixels
     * @param height Height of 3DRect in pixels.
     * @param raise true is 3DRect raises upward, false
     *  if 3DRect is to appear inset.
     * @param thickness The thickness of the 3D border.
     */
    public static void draw3DRect(Graphics g, int x, int y, int width, int height, boolean raise, int thickness) {
        int w = width;
        int h = height;

        for (int i = 0; i < thickness; i++) {
            g.draw3DRect(x + i, y + i, w - 2 * i, h - 2 * i, raise);
        }
    }
}

Related

  1. draw3DRect(Graphics g, int x, int y, int width, int height, int shadow, boolean raised)
  2. draw3DRect(Graphics2D g, int x, int y, int width, int height, Dimension depth)