Java Draw 3D Rectangle draw3DRect(Graphics2D g, int x, int y, int width, int height, Dimension depth)

Here you can find the source of draw3DRect(Graphics2D g, int x, int y, int width, int height, Dimension depth)

Description

Draw a 3D Rect.

License

Open Source License

Declaration

public static void draw3DRect(Graphics2D g, int x, int y, int width, int height, Dimension depth) 

Method Source Code


//package com.java2s;
/*/* w w  w .  j av a 2  s. com*/
 * Copyright (c) Leuville Objects All Rights Reserved.
 *
 * Leuville Objects MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Leuville Objects SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

import java.awt.*;

public class Main {
    /**
     * Draw a 3D Rect.
     */
    public static void draw3DRect(Graphics2D g, int x, int y, int width, int height, Dimension depth) {
        int p1x = x;
        int p1y = y;
        int p2x = x + width - 1;
        int p2y = p1y;
        int p3x = p2x;
        int p3y = y + height - 1;
        int p4x = x - depth.width + width - 1;
        int p4y = y + depth.height + height - 1;
        int p5x = x - depth.width;
        int p5y = p4y;
        int p6x = p5x;
        int p6y = y + depth.height;
        int p7x = p4x; // front top right
        int p7y = p6y;
        g.drawLine(p1x, p1y, p2x, p2y);
        g.drawLine(p2x, p2y, p3x, p3y);
        g.drawLine(p3x, p3y, p4x, p4y);
        g.drawLine(p4x, p4y, p5x, p5y);
        g.drawLine(p5x, p5y, p6x, p6y);
        g.drawLine(p6x, p6y, p1x, p1y);
        g.drawLine(p6x, p6y, p7x, p7y);
        g.drawLine(p7x, p7y, p2x, p2y);
        g.drawLine(p7x, p7y, p4x, p4y);
    }
}

Related

  1. draw3DRect(Graphics g, int x, int y, int width, int height, boolean raise, int thickness)
  2. draw3DRect(Graphics g, int x, int y, int width, int height, int shadow, boolean raised)