jeudi 16 novembre 2017

Loop not randomizing colors

I am trying to get the colors for each parameter in this loop to randomize in each iteration, however it only generates a random color for each value and repeats it the desired amount of times. Could someone point me in the correct direction for getting each iteration to generate new colors. Here is the code for my grid where the randomization is supposed to occur.

public class SmileyGrid extends JFrame implements ActionListener
{
    static SmileyGrid newGrid = new SmileyGrid();
    // Set up random colors
    Random ranColor = new Random();
    Color outline = new Color(ranColor.nextInt(256), ranColor.nextInt(256), ranColor.nextInt(256));
Color skin = new Color(ranColor.nextInt(256), ranColor.nextInt(256), ranColor.nextInt(256));
Color eyes = new Color(ranColor.nextInt(256), ranColor.nextInt(256), ranColor.nextInt(256));
Color smile = new Color(ranColor.nextInt(256), ranColor.nextInt(256), ranColor.nextInt(256));

public static void main(String[] args)
{
    newGrid.setSize(380, 380);
    newGrid.setLayout(new GridLayout(3, 3));
    newGrid.createGUI();
    newGrid.setVisible(true);
}

SmileyGrid()
{

}

private void createGUI()
{
    // Loop to create grid of faces
    for(int i = 0; i < 9; i++)
    {
        // Create faces
        Smiley faces = new Smiley(outline, skin, eyes, smile);
        newGrid.add(faces);
    }
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent ae)
{}

}




Aucun commentaire:

Enregistrer un commentaire