access to an array at a random index point, to compare to another random...
I don't know if there is another forum out there that will answer my qestion, so if anyone can point metoward it i would be very gratefull.
In the meantime however here is my problem.
I have been coding a GUI window to demonstrate the Stroop Effect (see this link http://en.wikipedia.org/wiki/Stroop_task for details of the Stroop Effect).
In essence I need to add a bunch of words (Red, Blue, Yellow, Green) to a window and have the colour of the typeface in a colour that is not the same as the word (hence the word "Red" will display in any colour other than "Red").
Well I have been able to get everything to work as desired, but decided that for a bit of fun I would go one step further.
what I have done is the following.
Created some arrays
String[] word = {"Blue", "Red", "Green", "Yellow"};
Color[] color = {Color.blue, Color.red, Color.Green, Color.Yellow};
I have now attempted to add in a level of randomness for adding the item into the window.
I try to ensure that the word
and it's color
are not the same using the following code:
private String setColourOfWord()
{//start setColourOfWord
String c = this.getColourOfWord();
String w = displayColour.toString();
boolean bool = c.equalsIgnoreCase(w);
/*set details for random number generation between 0 -4
*used for determining the index of the details to be sent to the
*paint method.
*/
while (bool)
{//start while
c = this.getColourOfWord();
bool = c.equalsIgnoreCase(w);
System.out.println("word is" + c +"colour is " + w);
}//end while
return c;
}//end setColourOFWord
/*
*Private helper methos related to setColourOfWord(), but in this
*instance the information returned is the colour that the font
*shall appear in.
*
*
*This method also checks that the displayColour is not the same as the
*word (eg Blue will not appear in Blue, but only in Red, Yellow or
*Green)
*
*/
private String getColourOfWord()
{//get colourOfWord
int i;
Random r =new Random();
i = r.nextInt(3);
String[] myStringArray ={"Blue",
"Red",
"Yellow",
"Green"};
colourOfWord = myStringArray[i];
return colourOfWord;
}//end getcolourof word
private Color getDisplayColour()
{//get displayColour
int i;
Random r =new Random();
i = r.nextInt(3);
Color[] myColourArray ={Color.BLUE,
Color.RED,
Color.YELLOW,
Color.GREEN};
displayColour = myColourArray[i];
return displayColour;
}//end get displayColour
the three methods
setColourOfWord()
getColourOfWord()
getDisplayColour()
are all utilised by the paintComponent() method
publicvoid paintComponent(Graphics g)
{//start paint
int i=1;
//System.out.println(setColours());
//this.setColours();
System.out.println("in paint" + i);
Font stroopFont =new Font("Serif", Font.BOLD,18);
g.setFont(stroopFont);
g.setColor(this.getDisplayColour());
g.drawString(this.setColourOfWord(), 25, 25);
i++;
}//start paint
When I run this code I regularly get a word (eg Red) appearing in the colour RED -
Can anyone help me understand where I am going wrong and what the solution would be.
The whole of the code for the project can be posted if required.
thanks for all the help in advance.
Dave

