by Dr. M. Halfpap
Zurück zur Hauptseite
public class Anima_mit_Stop extends Anima implements Runnable
{ Thread thread;
Graphics g;
}
public void button1_ActionEvents()
{ stop = true; }
public void paint(Graphics g)
{ // muß überschrieben werden, sonst ruckelige Ausgabe
// und kein Stoppen möglich
}
public void run()
{ g = this.getGraphics();
malen(g);
}
public void start()
{ if (thread == null)
{ thread = new Thread(this);
thread.start();
}
}
public void stop()
{ if (thread != null)
{ thread.stop();
thread = null;
}
}
public void malen(Graphics g)
{
int bildbreite = 50;
int bildhoehe = 50;
int xpos = 10;
int ypos = 10;
do
{ for (int i = 0; i<1000; i++)
{ if (stop==true) {break;}
g.drawImage(bild, (int)(xpos+(i/2)), (int)(ypos),
(int)(bildbreite*(1+(i/1000))), (int)(bildhoehe*(1+(1/1000))), this);
pause(3);
}
for (int i = 1000; i>0; i--)
{ if (stop==true) {break;}
g.drawImage(bild, (int)(xpos+(i/2)), (int)(ypos),
(int)(bildbreite), (int)(bildhoehe), this);
pause(3);
}
} while (stop == false);
}