Stroke stroke4 = new BasicStroke(4f, BasicStroke.CAP_SQUARE,īasicStroke.JOIN_MITER, 1.0f, dashingPattern3, 0. The constructor of this class accept the information about the rectangle x, y coordinates and its width and height. To draw a rectangle we use the Rectangle2D.Double static-inner class. Public class RectanglesDrawingExample extends JFrame You can see the snippet in the paintComponent (Graphics g) method defined in the anonymous JPanel object. * This program demonstrates how to rectangles using Graphics2D object. To demonstrate the examples, we create the following Swing program: /** arcWidth and arcHeight: specify the horizontal and vertical diameters of the arcs at the four corners when drawing a rectangle with rounded corners.Rectangle2D is the base class of Rectangle (for integer coordinates) Rectangle2D.Double (for double coordinates) and Rectangle2D.Float (for float coordinates).raised: specifies whether the rectangle edges are raised or sunk when drawing a 3D rectangle.width and height: specify dimension of the rectangle.( x, y) is the upper left corner of the rectangle.drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight).draw3DRect(int x, int y, int width, int height, boolean raised).drawRect(int x, int y, int width, int height).In Java, to draw a rectangle (outlines) onto the current graphics context, we can use the following methods provided by the Graphics/ Graphics2D class:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |