/* Copyright 2001 Michael R. Wick */ package Controls; import java.awt.*; import java.awt.event.*; import java.util.Vector; import Scopes.*; public class KaleidoscopeControl extends Panel implements Runnable { Vector theScopes; boolean inAutoMode; Button turnButton, runButton, stopButton; Thread animator; public KaleidoscopeControl(Kaleidoscope kal) { theScopes = new Vector(); theScopes.addElement(kal); setLayout( new FlowLayout() ); setBackground( Color.lightGray ); turnButton = new Button("Turn"); runButton = new Button("Run"); stopButton = new Button("Stop"); add(turnButton); add(runButton); add(stopButton); turnButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ for(int i =0; i < theScopes.size(); i++){ ((Kaleidoscope)(theScopes.elementAt(i))).turn(); } } }); stopButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ stop(); } } ); runButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ start(); } } ); inAutoMode = false; } public void start(){ animator = new Thread(this); inAutoMode = true; animator.start(); } public void stop(){ if (animator != null){ animator.stop(); } } public void register( Kaleidoscope k ){ theScopes.addElement(k); } public void run(){ while (inAutoMode){ for(int i = 0; i < theScopes.size(); i++){ ((Kaleidoscope)(theScopes.elementAt(i))).turn(); } try{ animator.sleep(500); } catch (Exception e){ e.printStackTrace(); System.exit(0); } } } }