Java examples for 2D Graphics:Rectangle
Draws a 3d frame around the designated rectangle.
/*/*from w w w . j a va2s.c o m*/ * @(#) GUIUtils * * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement. * Contributors retain copyright to elements licensed under a Contributor Agreement. * Licensed to the User under the LGPL license. * */ //package com.java2s; import java.awt.*; public class Main { /** * Draws a 3d frame around the designated rectangle. * * @param g The graphics context that will be drawn upon. * @param rect The rectangle that marks the bounds of the 3d frame * @param colorBackground The background color that will be painted within * the frame. */ public static void draw3DFrame(Graphics g, Rectangle rect, Color colorBackground, Color colorDark, Color colorLight) { Color colorOld = g.getColor(); // Fill Background Area g.setColor(colorBackground); g.fillRect(rect.x, rect.y, rect.width, rect.height); // Draw borders g.setColor(colorDark); // __ // x__| // g.drawLine(rect.x, rect.y, rect.x, rect.y + (rect.height - 1)); // xx // |__| // g.drawLine(rect.x, rect.y, rect.x + (rect.width - 1), rect.y); g.setColor(colorLight); // __ // | | // xx g.drawLine(rect.x + 1, rect.y + (rect.height - 1), rect.x + (rect.width - 1), rect.y + (rect.height - 1)); // __ // |__x // g.drawLine(rect.x + (rect.width - 1), rect.y + 1, rect.x + (rect.width - 1), rect.y + (rect.height - 1)); g.setColor(colorOld); } }