import java.awt.*; public class RedGreenThreadV10 extends Thread { public RedGreenThreadV10(Canvas c) { this.c = c; // passing the canvas in } // RedGreenThread public void run() { Graphics gc = c.getGraphics(); amRunning = true; while (true) { if (amRunning == true) { paint(gc); } else try { sleep(50); } catch (Exception e) {}; } // while } // run public void paint(Graphics gc) { gc.setColor(new Color(200, 50, 50)); gc.fillRect(5,5,90,40); try { sleep(50); } catch (Exception e) {}; // delay before showing next color gc.setColor(new Color(50, 200, 50)); gc.fillRect(5,5,90,40); try { sleep(50); } catch (Exception e) {}; // delay before showing next color gc.drawString("hello world!",50,50); } // paint public void mySuspend() { amRunning = false; } // mySuspend public void myResume() { amRunning = true; } // myResume // instance variables private Canvas c; private boolean amRunning = false; } // RedGreenThread