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

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

Description

draw D Rect

License

Open Source License

Declaration

public static void draw3DRect(Graphics g, int x, int y, int width, int height, int shadow, boolean raised) 

Method Source Code

//package com.java2s;
/*************************************************************************
 * Clus - Software for Predictive Clustering                             *
 * Copyright (C) 2007                                                    *
 *    Katholieke Universiteit Leuven, Leuven, Belgium                    *
 *    Jozef Stefan Institute, Ljubljana, Slovenia                        *
 *                                                                       *
 * This program is free software: you can redistribute it and/or modify  *
 * it under the terms of the GNU General Public License as published by  *
 * the Free Software Foundation, either version 3 of the License, or     *
 * (at your option) any later version.                                   *
 *                                                                       *
 * This program is distributed in the hope that it will be useful,       *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 * GNU General Public License for more details.                          *
 *                                                                       *
 * You should have received a copy of the GNU General Public License     *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 *                                                                       *
 * Contact information: <http://www.cs.kuleuven.be/~dtai/clus/>.         *
 *************************************************************************/

import java.awt.*;

public class Main {
    public static void draw3DRect(Graphics g, int x, int y, int width, int height, int shadow, boolean raised) {
        Color c = g.getColor();/*w ww .  j  a  v a2  s .  c om*/
        Color brighter = c.brighter();
        Color darker = c.darker();

        // upper left corner
        g.setColor(raised ? brighter : darker);
        for (int i = 0; i < shadow; i++) {
            g.drawLine(x + i, y + i, x + width - 1 - i, y + i);
            g.drawLine(x + i, y + i, x + i, y + height - 1 - i);
        }
        // lower right corner
        g.setColor(raised ? darker : brighter);
        for (int i = 0; i < shadow; i++) {
            g.drawLine(x + i, y + height - 1 - i, x + width - 1 - i, y + height - 1 - i);
            g.drawLine(x + width - 1 - i, y + height - 1 - i, x + width - 1 - i, y + i);
        }
        g.setColor(c);
    }
}

Related

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