Friday, July 12, 2024

Round Corners Rectangle Java Swing

 // Drawing Rectangles Using Rounded Corners Swing

import java.awt.*;

import javax.swing.*;


public class roundRectangle extends JFrame

{

public roundRectangle()

{

super("RoundRectangle Drawing Example");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(550,280);

setVisible(true);

}

void drawRoundRectangle(Graphics g)

{

Graphics2D g2d=(Graphics2D)g;

int x=55;

int y=60;

int width=450;

int height=170;

int arcWidth=30;

int arcHeight=30;


g2d.setColor(Color.ORANGE);

g2d.fillRoundRect(x,y,width,height,arcWidth,arcHeight);


g2d.setColor(Color.WHITE);

g2d.fillRoundRect(x+20,y+20,width-40,height-40,arcWidth+20,arcHeight);


g2d.setColor(Color.GREEN);

g2d.fillRoundRect(x+40,y+40,width-80,height-80,arcWidth+60,arcHeight);

}

public void paint(Graphics g)

{

super.paint(g);

drawRoundRectangle(g);

}

public static void main(String args[])

{

new roundRectangle();

}

}


Output :-