In this section, you will see how to draw colorful shapes in java swing.
In this section, you will see how to draw colorful shapes in java swing.In this section, you will see how to draw colorful shapes in java swing. There are various colorful shapes have been drawn in the given program. This program has used various types of methods to draw shapes and fill these with the appropriate color. Following are some methods are using in the given program to complete the required result. Pictorial representation for the result is given below:
drawRect():
This is the method of the Graphics class
(The Graphics class is used to drawing different-different type of
shapes). This method draws the rectangle. It takes some integer value as
parameter. This method is written like : Graphics.drawRect(x,
y, height, width);.
x - This is the variable represents the row no. or the
x - coordinate.
y - This is also a variable represents the column no. or the y - coordinate.
drawOval():
This is the method of the Graphics class
which draws the oval on the frame. This method takes argument same as the
drawRect() method. In this method first come the width and then height is specified.
fillRect():
This is the method of the Graphics class which is
used to fill rectangle with the specified color which is set before using the
setColor() method of the Graphics class. It also takes argument same as
the drawRect() method.
fillOval():
This is also the method of the Graphics
class which is used to fill the oval with color specified in the setColor()
method before. This method also takes argument same as the drawOval() method.
Here is the code of program:
import javax.swing.*;
|
Ads