Bounds a color parameter to between 0 and 255 (both inclusive). - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Bounds a color parameter to between 0 and 255 (both inclusive).

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int color = 2;
        System.out.println(checkColor(color));
    }//from w w w . j av a2  s .  c o  m

    /**
     * Bounds a color parameter to between 0 and 255 (both inclusive).
     * 
     * @param color
     *            the parameter to bound.
     * @return color, if 0<=color<=255, 255 if color>255, 0 if color<0
     */
    public static int checkColor(int color) {
        if (color < 0) {
            return 0;
        }
        if (color > 255) {
            return 255;
        }
        return color;
    }
}

Related Tutorials