Good morning, I have a problem. I need to manipulate a variable that is modificated in a thread.
new Timer(5000, new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
color=colorRandom();
}
}).start();
Where: color is a global variable that is set on white, colorRandom() is a method that generates and returns a random Color (black, white or red).
Finally I tried to check if the ellipse's color (another object) is the same of rectangle's. So I did this:
public boolean checkColor()
{
return ellipseColor.equals(rect.color);
}
This does not work. It doesn't return me the right value. Even if the two object's have the same color it says that the colors are different. Also I tried this after setting the ellipse's and rectangle's color both to white
public boolean checkColor()
{
return ellipseColor.equals(rect.color);
}
This returns true! so the method checkColor appears to be OK. The problem, in the first case, is that the variable is not correctly manipulated. Any suggestions? I tried also with the locks because a friend told me to try it but it still does not function.