// Page 261-263 import java.awt.Graphics; import java.applet.Applet; import java.awt.Color; public class CellDiv extends Applet implements Runnable { Thread mythread=null; int flag =0; public void start() { mythread =new Thread(this); mythread.start(); } public void run() { while(true) { for(flag=0;flag<=6;flag++) { repaint(); try { mythread.sleep(2000) ; } catch(InterruptedException e) { } } } } public void stop() { mythread.stop(); mythread=null; } public void paint(Graphics g) { if (flag == 0) { g.setColor(Color.red) ; g.fillOval(50, 50,100,100); g.setColor(Color.blue) ; g.fillOval(75, 75,50,50); } else if (flag == 1) { g.setColor(Color.red) ; g.fillOval(50, 50,138,100); g.setColor(Color.blue) ; g.fillOval(80, 75,50,50); g.fillOval(107, 75,50,50); } for(int i=2; i<=6; i++) if(flag==i) Disp(g, flag-2); } public void Disp (Graphics g, int offset) { g.setColor(Color.red) ; g.fillOval(50, 50,100,100); g.fillOval(90+17*offset, 50,100,100); g.setColor(Color.blue) ; g.fillOval(75, 75,50,50); g.fillOval(117+17*offset, 75,50,50); } }