Here you can find the source of drawFilledBox(Graphics2D g, int x, int y, int width, int height)
Parameter | Description |
---|---|
g | The graphics context to use |
x | The left side of the box |
y | The top of the box |
width | The box's width |
height | The box's height |
public static void drawFilledBox(Graphics2D g, int x, int y, int width, int height)
//package com.java2s; //License from project: Open Source License import java.awt.*; public class Main { public static final int BEVEL_CORNER_TOP_LEFT = 0xf01; public static final int BEVEL_CORNER_TOP_RIGHT = 0xf02; public static final int BEVEL_CORNER_BOTTOM_RIGHT = 0xf04; public static final int BEVEL_CORNER_BOTTOM_LEFT = 0xf08; public static final int DEFAULT_BEVEL_CORNERS = BEVEL_CORNER_TOP_LEFT | BEVEL_CORNER_BOTTOM_RIGHT; public static final int DEFAULT_BEVEL_AMOUNT = 5; /**//from w w w. ja v a2s. c o m * Draw a filled box, with some of the edges beveled * @param g The graphics context to use * @param x The left side of the box * @param y The top of the box * @param width The box's width * @param height The box's height */ public static void drawFilledBox(Graphics2D g, int x, int y, int width, int height) { Polygon p = new Polygon(); int bevel_amount = DEFAULT_BEVEL_AMOUNT; if (width < bevel_amount * 2) bevel_amount = width / 2; if (height < bevel_amount * 2) bevel_amount = height / 2; // Top left if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_TOP_LEFT) == BEVEL_CORNER_TOP_LEFT) { p.addPoint(x, y + bevel_amount); p.addPoint(x + bevel_amount, y); } else p.addPoint(x, y); // Top right if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_TOP_RIGHT) == BEVEL_CORNER_TOP_RIGHT) { p.addPoint(x + width - bevel_amount, y); p.addPoint(x + width, y + bevel_amount); } else p.addPoint(x + width, y); // Bottom right if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_BOTTOM_RIGHT) == BEVEL_CORNER_BOTTOM_RIGHT) { p.addPoint(x + width, y - bevel_amount + height); p.addPoint(x + width - bevel_amount, y + height); } else p.addPoint(x + width, y + height); // Bottom left if ((DEFAULT_BEVEL_CORNERS & BEVEL_CORNER_BOTTOM_LEFT) == BEVEL_CORNER_BOTTOM_LEFT) { p.addPoint(x + bevel_amount, y + height); p.addPoint(x, y + height - bevel_amount); } else p.addPoint(x, y + height); g.fill(p); } }