Java Random Color getRandomColor()

Here you can find the source of getRandomColor()

Description

get Random Color

License

Open Source License

Declaration

public static Color getRandomColor() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;

public class Main {
    private static ArrayList<Color> COLOR_INVENTORY = new ArrayList<Color>();
    private static Random r = new Random();

    public static Color getRandomColor() {
        if (COLOR_INVENTORY.size() == 0) {
            initializeColorInventory();//  w w w . java  2  s . c om
        }
        return COLOR_INVENTORY.get(r.nextInt(COLOR_INVENTORY.size()));
    }

    public static void initializeColorInventory() {
        COLOR_INVENTORY = new ArrayList<Color>();
        COLOR_INVENTORY.add(Color.RED);
        COLOR_INVENTORY.add(Color.BLUE);
        COLOR_INVENTORY.add(Color.GREEN);
        COLOR_INVENTORY.add(Color.YELLOW);
    }
}

Related

  1. getRandomColor()
  2. getRandomColor()
  3. getRandomColor()
  4. getRandomColor()
  5. getRandomColor()
  6. getRandomColor()
  7. getRandomColor()
  8. getRandomColor()
  9. getRandomColor(boolean useTransparency)