Here you can find the source of getRandomColor()
public static Color getRandomColor()
//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); } }