Java examples for 2D Graphics:Rectangle
round Rectangle
//package com.java2s; import java.awt.*; public class Main { public static void roundRectangle(Graphics g, int x1, int y1, int x2, int y2, int rtl, int rtr, int rbl, int rbr, boolean top, boolean right, boolean bottom, boolean left) { // top left edge if (top && left) { g.drawArc(x1, y1, 2 * rtl, 2 * rtl, 90, 90); }/*from w ww.ja v a2 s.c o m*/ // top right edge if (top && right) { g.drawArc(x2 - 2 * rtr, y1, 2 * rtr, 2 * rtr, 0, 90); } // bottom left edge if (bottom && left) { g.drawArc(x1, y2 - 2 * rbl, 2 * rbl, 2 * rbl, 180, 90); } // bottom right edge if (bottom && right) { g.drawArc(x2 - 2 * rbr, y2 - 2 * rbr, 2 * rbr, 2 * rbr, 270, 90); } // horizontal if (top) { g.drawLine(x1 + rtl, y1, x2 - rtr, y1); } else { // draw dashed line if (left) { g.drawLine(x1, y1, x1, y1 + rtl); } if (right) { g.drawLine(x2, y1, x2, y1 + rtr); } } if (bottom) { g.drawLine(x1 + rbl, y2, x2 - rbr, y2); } else { // draw dashed line if (left) { g.drawLine(x1, y2 - rbl, x1, y2); } if (right) { g.drawLine(x2, y2 - rbr, x2, y2); } } // vertical if (left) { g.drawLine(x1, y1 + rtl, x1, y2 - rbl); } if (right) { g.drawLine(x2, y1 + rtr, x2, y2 - rbr); } } }