<< Chapter < Page Chapter >> Page >

Compare constructor parameters with upper-right quadrant

Now consider the parameter values used in Listing 7 and compare them with the image in the upper-right quadrant in

A simple color paint versus a gradient paint

Listing 6 passes an object of the simple Color class representing the color green to the setPaint method.

Listing 7 passes an object of the GradientPaint class to the setPaint method.

Therefore, we need to understand the behavior of an object of the GradientPaint class.

Constructor parameters

There are four overloaded constructors for the GradientPaint class. The constructor highlighted in yellow in Listing 7 is one of the most complicated. It requires the following parameters:

  • x1 - x coordinate of the first specified Point in user space
  • y1 - y coordinate of the first specified Point in user space
  • color1 - Color at the first specified Point
  • x2 - x coordinate of the second specified Point in user space
  • y2 - y coordinate of the second specified Point in user space
  • color2 - Color at the second specified Point
  • cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

Two points and two colors

Basically, the class allows you to specify two points and two colors (plus one additional boolean parameter) when you construct an object of the class.

One of the colors is associated with each point.

An imaginary line segment

Think of the two points as being at the ends of an imaginary line segment, which can be at any angle relative to the horizontal.

Colors at the ends of the line segment

When a shape is drawn using a gradient fill, one of the colors will appear at one end of the line segment and the other color will appear at the other end ofthe line segment.

The color will change

The color will change from one color to the other along the imaginary line segment connecting the two points.

Perpendicular color bands on the sides

The colors extend out to the sides of the imaginary line segment in bands that are perpendicular to the line segment.

The cyclic parameter

If the last (cyclic) parameter is set to false, the color will only change along the imaginary line segment. Areas beyond each end of the linesegment will be the colors that are specified for the points at the ends of the line segment.

(This parameter was not set to false for any of the circles in Figure 1 .)

If the cyclic parameter is true...

The pattern of color change that occurs along the line segment will extend in a cyclic fashion beyond the ends of the line segment all the way to infinity.

Compare constructor parameters with upper-right quadrant

Now consider the parameter values used in Listing 7 and compare them with the image in the upper-right quadrant in Figure 1 .

The location of the first point

The diameter of each circle in Figure 1 is 128 pixels. The first point for the upper-right quadrant in Figure 1 is on the X axis at the point where the circle touches the X axis. This point is specified to have a color of green.

The location of the second point

The second point is 32 pixels directly above the first point. Therefore, the imaginary line segment is perpendicular to the X axis. It extends from the Xaxis one-fourth of the way to the top of the circle. The second point is specified to have a color of blue.

Questions & Answers

how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask