1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* 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
Add Comment