// this version works with Java 1.0 (e.g. VJ++ 1.1) import java.awt.*; import java.applet.*; // this version doesn't have thread public class RedGreenV110 extends Applet { public void init() { setLayout(new BorderLayout(2,2)); b = new Button("start"); c = new Canvas(); add("West", b); add("Center", c); } // init public void paint(Graphics g) { Graphics gc = c.getGraphics(); while (keepGoing) { gc.setColor(new Color(200, 50, 50)); gc.fillRect(5,5,90,40); gc.setColor(new Color(50, 200, 50)); gc.fillRect(5,5,90,40); } // while } // paint public boolean handleEvent(Event ae) { if (ae.id == Event.WINDOW_DESTROY) System.exit(0); return super.handleEvent(ae); } // handleEvent public boolean action(Event ae, Object s) { if (s.equals("start")) handleStart(); else if (s.equals("stop")) handleStop(); else return super.action(ae, s); return true; } // action private void handleStart() { keepGoing = true; b.setLabel("stop"); } // handleStart private void handleStop() { keepGoing = false; b.setLabel("start"); } // handlStop // instance variables private Button b; private Canvas c; private boolean keepGoing = false; } // RedGreenV110