I have three rectangles on my canvas. I wanted to change the colors of the three rectangles in slow order one by one. For example: when starting the application, the user should be able to see three rectangles with the same color (blue). After 2 seconds, the color of the rectangles should change to red. Again after 2 seconds, the next color of the rectangles should change. The latter is also performed in the same way, which means after 2 seconds the second rectangle.
I wrote in my own way. But that does not work. All recantals change together. I want one by one.
Can anyone give me logic.
final Runnable timer = new Runnable() {
public void run() {
for(int i = 0 ; i < rectangleList.size();i++){
if(rectangleListt.get(i).getBackgroundColor().equals(ColorConstants.blue)){
try {
rectangleList.get(i).setBackgroundColor(ColorConstants.yellow);
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
source
share