Drawing shapes using java graphics API | Razsoft Education

Shapes in java 

To draw shape in java, It provides shape interface. Any class that implement the shape interface will be used to draw shapes. To draw shapes we need to pass object of the class which implements the shape interface in the draw() of fill() method of graphics object. Outline of shape is known as path. 

    Java has already a list of class that implement the Shape interface to draw some basic geometrical shapes. Which is defined in to two main category Rectangular shape and non Rectangular shape. We can also implement shape interface in our own class to create custom shapes.  

Rectangular Shape 

Rectangular shapes are those shape which Extends the RectangularShape class. The class doesn't define any geometrical shape but it provide a rectangular frame to all the class that extend it. Here is list of some class that extends the RectengularShape class 

                     * Rectangle2D

 * RoundRectangle2D

 * Arc2D 

 * Ellipse2D 

       Draw and fill 

To paint any object we need to pass it into draw() or fill() method of the graphics object. draw() method only paint the outline of the shape on the graphics surface so, when we use draw() method only outline of the shape is visible on screen. When we use fill() method it paint the whole area that is covered by the shape on graphics surfaces so, we see a object filled with color on screen. 


 


            Rectangle using draw()                        Rectangle using fill() 
 

 

Comments

Popular posts

"climits" Header file in c++ programming language | Razsoft Education

Integer data type in C++ programming language | Razsoft education

Computer graphics with java an introduction | Razsoft Education