The RoundRectangle2D class lets you draw a rectangle with corners rounded. The construction of the box is identical to that made with the class Rectangle2D, the only difference in this case are two additional parameters to end of the constructor, which indicate the width and length of the curve defining each corner. The larger these values will have higher level of rounding the corners.
import javax.swing.*;
import java.awt.*;
public class JRoundRectanglesJavaExample extends JFrame
{
public void paint(Graphics gr)
{
super.paint(gr);
int x = 30;
int y = 50;
final int WIDTH = 90, HEIGHT = 100;
final int HORIZ_GAPP = 110;
gr.drawRoundRect(x, y, WIDTH, HEIGHT, 0, 0);
x += HORIZ_GAPP;
gr.drawRoundRect(x, y, WIDTH, HEIGHT, 30, 30);
x += HORIZ_GAPP;
gr.drawRoundRect(x, y, WIDTH, HEIGHT, 50, 50);
x += HORIZ_GAPP;
gr.drawRoundRect(x, y, WIDTH, HEIGHT, 90, 90);
}
public static void main(String[] ars)
{
JRoundRectanglesJavaExample frm = new JRoundRectanglesJavaExample();
frm.setSize(470, 200);
frm.setVisible(true);
}
}