Create Custom Color Using RGB Example
- /*
- Create Custom Color Using RGB Example
- This java example shows how to create a custom color using red, green
- and blue (RGB) components in an Applet window using Java AWT Color class.
- */
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Graphics;
- /*
- <applet code="CreateCustomColor" width=200 height=100>
- </applet>
- */
- public class CreateCustomColor extends Applet{
- public void paint(Graphics g) {
- /*
- * To create a custom color using RGB, use
- * Color(int red,int green, int blue)
- * constructor of Color class.
- */
- //this will create light blue color
- Color customColor = new Color(10,10,255);
- //set foreground color of an applet
- this.setForeground(customColor);
- g.drawString("This is a custom RGB color", 10, 50);
- }
- }
Example Output




