/* * XRunCanvas.java -- * * canvas that has some action going on. * * Copyright 1996 Regents of the University of California * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without * fee is hereby granted, provided that this copyright * notice appears in all copies. The University of California * makes no representations about the suitability of this * software for any purpose. It is provided "as is" without * express or implied warranty. * * rcsid = "$Header: /disks/barad-dur/now/rywang/src/java/classes/ryw/XPict.java,v 1.1 1995/09/27 07:33:22 rywang Exp $ xFS (Berkeley)" */ package ryw; import java.awt.*; import java.awt.image.*; /** * A Canvas that repaints itself once in a while. */ public abstract class XRunCanvas extends Canvas implements Runnable { Thread kicker = null; boolean die = false; int sleep = 3; public void initialize (int sleepSecs) { die = false; sleep = sleepSecs; } public void start () { die = false; if (kicker != null) return; kicker = new Thread (this); kicker.start (); } public void run () { while (!die) { repaint (); try { Thread.sleep (sleep*1000); } catch (InterruptedException e) { break; } } } public void stop () { die = true; if (kicker != null) { kicker.stop (); kicker = null; } } }