/* * Authors: Dietolf Ramm * Date: 4/1/02 * Course: CPS 4 * Purpose: PRACTICE JAVA */ public class Clock extends GP.Behaviors.TimeLimited { GP.Attributes.Values.Counter myLeft; GP.Attributes.Values.Counter myRight; public Clock (GP.Attributes.Values.Counter left, GP.Attributes.Values.Counter right, double minutes) { myLeft = left; myRight = right; SetLimit(minutes*60); SetDelay(1); // delay 1 second between calls to Step myLeft.Reset(); myLeft.Increment(minutes); myRight.Reset(); } public void Step() { if (myRight.GetValue() == 0) { myLeft.Increment(-1); myRight.Increment(59); } else myRight.Increment(-1); } public void Stop() { myLeft.Reset(); myRight.Reset(); GP.Shapes.Oval o = new GP.Shapes.Oval(); o.SetPosition(new GP.Attributes.Coordinate(200,200)); o.SetSize(new GP.Attributes.Dimension(200)); o.SetColor(new GP.Attributes.Colors.Red()); } }