How come this doesn't work?
Hello Mates!I'm playing around with Threads and animation, so first, please take a look at:
http://www.eksperten.dk/spm/491679
...and I really want some comments even if it just is guesses or great laughs ;-)
But I thougt that I could change it and get the same functionality with this code for the animation but no, it didn't.
try
{
Thread.sleep(50);
repaint();
}
catch(Exception e)
{
e.printStackTrace();
}
I removed the Runnable and called the flipCard from the mouseListener. So if any one could explain why I did not get the same result it would be great.
Best regards
Fredrik
The flipCard looks like this now:
public void flipCard()
{
if(flipToFront)
{
int x1 = 20;
int y1 = 20;
int x2 = 95;
int y2 = 120;
int moveer = 0;
for(int i = 0; i < 5; i++)
{
System.out.println(i);
backGraphics.drawImage(background, 0, 0, this);
if(i<3)
{
x1 = x1+10;
x2 = x2-10;
}
else if(i==3)
{
x1 = x1+5;
x2 = x2-5;
}
else if(i==4)
{
x1 = x1+4;
x2 = x2-4;
}
moveer = moveer + 13;
backGraphics.drawImage(cardbackside, x1+moveer, y1, x2+moveer, y2, 0, 0, 75, 100, this);
try
{
Thread.sleep(50);
repaint();
}
catch(Exception e)
{
e.printStackTrace();
}
}
for(int i = 0; i < 5; i++)
{
System.out.println(i);
backGraphics.drawImage(background, 0, 0, this);
if(i==0)
{
x1 = x1-4;
x2 = x2+4;
}
else if(i==1)
{
x1 = x1-5;
x2 = x2+5;
}
else if(i>1)
{
x1 = x1-10;
x2 = x2+10;
}
moveer = moveer + 13;
backGraphics.drawImage(cardfrontside, x1+moveer, y1, x2+moveer, y2, 0, 0, 75, 100, this);
try
{
Thread.sleep(50);
repaint();
}
catch(Exception e)
{
e.printStackTrace();
}
}
flipToFront = false;
}
else
{
int x1 = 150;
int y1 = 20;
int x2 = 225;
int y2 = 120;
int moveer = 0;
for(int i = 0; i < 5; i++)
{
System.out.println(i);
backGraphics.drawImage(background, 0, 0, this);
if(i<3)
{
x1 = x1+10;
x2 = x2-10;
}
else if(i==3)
{
x1 = x1+5;
x2 = x2-5;
}
else if(i==4)
{
x1 = x1+4;
x2 = x2-4;
}
moveer = moveer + 13;
backGraphics.drawImage(cardfrontside, x1-moveer, y1, x2-moveer, y2, 0, 0, 75, 100, this);
try
{
Thread.sleep(50);
repaint();
}
catch(Exception e)
{
e.printStackTrace();
}
}
for(int i = 0; i < 5; i++)
{
System.out.println(i);
backGraphics.drawImage(background, 0, 0, this);
if(i==0)
{
x1 = x1-4;
x2 = x2+4;
}
else if(i==1)
{
x1 = x1-5;
x2 = x2+5;
}
else if(i>1)
{
x1 = x1-10;
x2 = x2+10;
}
moveer = moveer + 13;
backGraphics.drawImage(cardbackside, x1-moveer, y1, x2-moveer, y2, 0, 0, 75, 100, this);
try
{
Thread.sleep(50);
repaint();
}
catch(Exception e)
{
e.printStackTrace();
}
}
flipToFront = true;
}
}
