Vergleich Timer ̶ Thread
Timer Thread
class … implements ActionListener Interface class … implements Runnable
Timer tim = new Timer (ms, this);
tim.start ();
im Konstruktor Thread th = new Thread (this);
th.start ();
// wird periodisch aufgerufen
void actionPerformed (ActionEvent e) {
// Aktion }
Interface-Methode
// wird in eigenem Thread gestartet void run ()
{
while (true) {
// Aktion try
{
Thread.sleep (ms);
}
catch (InterruptedException e) { }
} }