random Color - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

random Color

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int size = 2;
        System.out.println(java.util.Arrays.toString(randomColor(size)));
    }/*  www . j a v  a  2  s. c o m*/

    public static int[] colors = new int[] { 0xFF9B5A09, 0xFFD4A3FA,
            0xFF7A1C5A, 0xFF476E95, 0xFFC7B43F, 0xFFA4842F };

    public static int[] randomColor(int size) {
        int[] returncolors = new int[size];
        for (int i = 0; i < size; i++) {
            returncolors[i] = colors[(int) (Math.random() * 6)];
        }
        return returncolors;
    }
}

Related Tutorials