In this section, you will learn how to draw the colorful gradient shapes. First of all you will know about the gradient color. The gradient color is combination of more than one colors to design graphics. Object with the gradient color looks like a 3-D component. The object colored with gradient color makes it more attractive. The screen shot is given below:
Here you will see the gradient colors have been used in the Rectangle with the help of this program. Program draws a rectangle using Graphics2D and GradientPaint().
The Gradient color uses the following methods:
This is the class which extends from the Graphics class i.e. used to control the geometry according to the coordinate. It is also used to manage texts.
This is a constructor of Gradient class. It is used to create a gradient color with the help of getGradient() method.
This is a constructor of Gradient class. It used to fill the gradient color in the shapes.
Syntax for GradientPaint:
GradientPaint(startX, startY, startColor, endX, endY, endColor, true)
startX - It represents the X-coordinate of the
startY - It represents the Y-coordinate of thestarting point.
startColor - It is used to set the starting color of the shape.
endX - It represents the X-coordinate of the ending point.
endY - It represents the Y- coordinate of the ending point.
endColor - It is used to set the ending color of the shape.
true - It is a boolean value mentioned for the cyclic presentation of color in the shape mean the starting color and the ending color are repeated up to the size of the shape.
Here is the code of program:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial