Thursday, November 6, 2014

Java using Color pro



Create Custom Color Using HSB

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class CreateCustomColorUsingHSB extends Applet
{
public void paint(Graphics g)
{
Color customColor = Color.getHSBColor(0.9f,0.5f,0.8f);
this.setForeground(customColor);
g.drawString("This is a custom HSB color", 10, 50);
   }
}

Create Custom Color Using RGB

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class CreateCustomColor extends Applet
{
public void paint(Graphics g)
{
Color customColor = new Color(10,10,255);
this.setForeground(customColor);
g.drawString("This is a custom RGB color", 10, 50);
   }
}

Get Alpha Component of Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class GetAlphaComponent extends Applet
{
public void paint(Graphics g)
{
Color customColor = new Color(255,10,10);
int alpha = customColor.getAlpha();   
g.drawString("Alpha component : " + alpha, 10,50);
   }
}

Get Brighter Version of Current Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class GetBrighterColor extends Applet
public void paint(Graphics g)
{
Color customColor = new Color(255,10,10);
Color brighterColor = customColor.brighter();
this.setForeground(brighterColor);
g.drawString("Brighter Color", 80, 10);
   }
}

Get Darker Version of Current Color

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class GetDarkerColor extends Applet
{
public void paint(Graphics g)
{
Color customColor = new Color(255,10,10);
Color darkerColor = customColor.darker();
this.setForeground(darkerColor);
g.drawString("Darker Color", 80, 10);           
   }
}

Get Red, Green, and Blue Components from Color  

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class GetColorComponents extends Applet
{
public void paint(Graphics g)
{
Color customColor = Color.getHSBColor(0.9f,0.5f,0.8f);
int red, green, blue;
red = customColor.getRed();
green = customColor.getGreen();
blue = customColor.getBlue();        
g.drawString("Red:" + red +", Green:" + green + ", blue:" + blue, 10,50);
         
   }
}

No comments:

Post a Comment