/*
Get Red, Green, and Blue (RGB) Components From Color Example
This java example shows how to get Red, Green, and Blue (RGB) components
from color using Java AWT Color class.
*/
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
/*
<applet code="GetColorComponents" width=200 height=100>
</applet>
*/
public class GetColorComponents extends Applet{
public void paint(Graphics g){
//create a custom color using HSB
Color customColor = Color.getHSBColor(0.9f,0.5f,0.8f);
/*
* To get Red, Green, and Blue components from color use,
* int getRed()
* int getGreen() and
* int getBlue()
* methods of AWT Color class.
*/
int red, green, blue;
red = customColor.getRed();
green = customColor.getGreen();
blue = customColor.getBlue();
g.drawString("Red:" + red +", Green:" + green + ", blue:" + blue, 10,50);
}
}
Example Output

Bookmark/Search this post with: