by Dinesh Thakur Category: Swing

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)
                           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);

Round Rectangles in Java Swing Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles