Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;

public class Main {
    public static Color adjust2(Color original, double value, int maximumrange) {
        if (value > 1)
            value = 1;
        if (value < 0)
            value = 0;

        int r = original.getRed();
        int g = original.getGreen();
        int b = original.getBlue();

        double nah = value * maximumrange;

        r += (int) nah;
        g += (int) nah;
        b += (int) nah;

        r = colorSnap(r);
        g = colorSnap(g);
        b = colorSnap(b);
        return new Color(r, g, b, original.getAlpha());
    }

    /**
     * Snaps a rgba value to a byte.
     * @param rgbaval The integer to snap.
     * @return Between 0 and 255.
     */
    public static int colorSnap(int rgbaval) {
        if (rgbaval > 255)
            rgbaval = 255;
        if (rgbaval < 0)
            rgbaval = 0;
        return rgbaval;
    }
}