while ( running ) { repaint(); try { Thread.sleep( updateInterval ); } catch ( InterruptedException e ) { System.out.println("interrupted..."); return; } }
System.out.println("starting..."); if ( !running ) // naive approach { running = true; thread = new Thread(this); thread.start(); }
System.out.println("stopping..."); thread.interrupt(); running = false;