Showing posts with label Java Swing Custom Stroke Rectangle. Show all posts
Showing posts with label Java Swing Custom Stroke Rectangle. Show all posts

Friday, July 12, 2024

Custom Strokes Rectangle Java Swing

 // Drawing Rectangles Using Custom Strokes Swing

import java.awt.*;

import javax.swing.*;


public class CustomRectangle extends JFrame

{

public CustomRectangle()

{

super("Custom Rectangle Example");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(550,280);

setVisible(true);

}

void drawCustomRectangle(Graphics g)

{

Graphics2D g2d=(Graphics2D)g;

Stroke stroke1=new BasicStroke(6f);

g2d.setStroke(stroke1);


g2d.setColor(Color.RED);

g2d.drawRect(55,60,450,170);

}

public void paint(Graphics g)

{

super.paint(g);

drawCustomRectangle(g);

}

public static void main(String args[])

{

new CustomRectangle();

}

}


Output :-