Question

This is for Java. Explain how to use the Color class constructor to create custom colors.

This is for Java.

Explain how to use the Color class constructor to create custom colors.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Color class of package java.awt contains various constructors to create custom Colors. These constructors take in input the RGB values and create custom color according to RGB.

Some of the examples of using Color Class constructors is as follows : -

1) Color(float r, float g, float b) - this constructor gets 3 values in float for red green and blue component of RGB.

eg

                Color x= new Color( 223.5,123,12.45 );
                p.setBackground( x );

2)Color(float r, float g, float b, float a) . this is similar to first and it takes one more input a i.e. alpha whose range is 0.0-1.0

3)Color(int rgb) - it takes RGB as a single int value.

eg

Color x= new Color(135206250); // FOR SKY BLUE
                p.setBackground( x );

Other than that there are two more constructors , same as 1 and 2 with int values in place of float.

Add a comment
Know the answer?
Add Answer to:
This is for Java. Explain how to use the Color class constructor to create custom colors.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT