Write a statement to draw a rounded rectangle with the following features:
Width = 200 Corner horizontal diameter = 20
Height = 100 Corner vertical diameter = 40
Select the suitable upper-left corner of the rectangle.
This is the statement: g1.drawRoundRect(20, 40, 200, 100, 50, 30);
The code below illustrates the usage of the above statement.
package roundedrectangle;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RoundedRectangle extends JFrame{
public void paint(Graphics g){
Graphics2D g1= (Graphics2D) g;
g1.drawRoundRect(20, 40, 200, 100, 50, 30);
}
public static void main(String[] args) {
RoundedRectangle rec = new RoundedRectangle();
rec.setTitle("Rounded Rectangle ");
rec.setSize(350, 275);
rec.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rec.setLocationRelativeTo(null);
rec.setVisible(true);
}
}
Comments
Leave a comment