I want to animate the movement of a label that contains a truck image, i've seen some tutorial and everything works alright, but in my case the whole app gets i mean i want to move this truck from a starting point e.g. Truck.setBounds(0,0,50,50)
then to a next point, then to another next point, until it reaches its final destination e.g. Truck.setBounds(1210,0,50,50)
Here is my code
try
{
int x = 1;
while(true)
{
if(x==1)
truck.setBounds(35,35,50,50);
if(x==2)
truck.setBounds(245,35,50,50);
if(x==3)
truck.setBounds(445,35,50,50);
if(x==4)
truck.setBounds(645,35,50,50);
if(x==5)
truck.setBounds(845,35,50,50);
if(x==6)
truck.setBounds(1045,35,50,50);
if(x==7)
truck.setBounds(1245,35,50,50);
Thread.sleep(1000);
x++;
if(x==8)
break;
}
}
catch(Exception ee)
{
return;
}
Again as i already said, the whole application gets sleep, then when it reaches it final destination e.g. x==7
it appears on the screen, it never appears on starting destination & neither on the next destination etc.
Last thing i'm not very familiar with java nor java swing animation, if you could edit my code to make it works i would be very thankful.