Showing posts with label color constructor. Show all posts
Showing posts with label color constructor. Show all posts

Thursday, 27 February 2014

INTRODUCING THE AWT:Working With Color

Java supports color in a portable, device-independent fashion.


Working with Color

Java supports color in a portable, device-independent fashion. The AWT color system allows you to specify any color you want. It then finds the best match for that color, given the limits of the display hardware currently executing your program or applet. Thus, your code does not need to be concerned with the differences in the way color is supported by various hardware devices. Color is encapsulated by the Color class.


color constructors


To create your own colors,using one of the color constructors.the most commly used forms are shown here:

  • Color (int red, int green, int blue)
  • Color (int rgbValue) //int rgbValue = (0xff000000 | (0xc0<<16) | (0x00 <<8) | 0x00);
  • Color (float red, float green, float blue)

The first constructors take three integers that specify the color as the mix of red,green and blue. these values must be between 0 and 255.

example:
new color(255,100,100); // light red.


The second color constructor takes a single integer that contain the mix of red,greenand blue packed into an integer.the integer is organized with red in bits 16 to 23,green in bits 8 to 15,and blue in bits 0 to 7.