//StartStopClock.java

import java.awt.*;
import java.awt.event.*;
//import java.applet.*;
//import java.lang.*;

public class StartStopClock extends Panel {   
	//private static final Color bgcolor = new Color(216,216,191);
	//private static final Color bgcolor = new Color(236,236,221);
        private static final Color bgcolor = new Color(180,180,180); // beige
	
	//public ImageButton button1, button2;
	public Button button1, button2, button3;
        public boolean IsStop;
        
        public ClockCanvas clockcanvas;
	
	public StartStopClock(){
		super();
		setLayout(null);
                setBackground(bgcolor);
		
                button1 = new Button("START");
                button2 = new Button("STOP");
                button3 = new Button("RESET");
                
                button1.setBounds(11,18,46,20);
		button2.setBounds(75,18,46,20);
                button3.setBounds(139,18,46,20);
		
		button1.setBackground(Color.white);
                button2.setBackground(Color.white);
                button3.setBackground(Color.white);
                
                button1.setBackground(new Color(255,255,230));
                button2.setBackground(new Color(255,255,230));
                button3.setBackground(new Color(255,255,230));
                
                button1.setForeground(Color.green.darker());
                button2.setForeground(Color.red.darker());
                button3.setForeground(Color.yellow.darker());
                
                button1.setFont(new Font("SanSerif",Font.BOLD,11)); 
                button2.setFont(new Font("SanSerif",Font.BOLD,11)); 
                button3.setFont(new Font("SanSerif",Font.BOLD,11)); 
                
                clockcanvas = new ClockCanvas();
		clockcanvas.setBounds(135,3,50,50);
		add(button1);
		add(button2);
                add(button3);
                
		//add(clockcanvas);
                
                IsStop = true;
                
                button1.setEnabled(true);
                button2.setEnabled(false);
                button3.setEnabled(true);
	}
	
	public void paint(Graphics g){
            g.setColor(Color.white);
            g.fillRect(0,0,getSize().width,getSize().height);

            // Start - Stop button
            
            //-------------------------START BUTTON
            if(IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(35,30,38,g);
                //g.setColor(Color.green);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(33,28,38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(33,28,38,g);
                button1.setEnabled(true);
                button2.setEnabled(false);
                button3.setEnabled(true);
                // rectangles behind actual buttons
                g.setColor(Color.green.darker());
                g.fillRect(10,17,48,22);
            
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(35,30,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(33,28,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(33,28,38,g);
                button1.setEnabled(false);
                button2.setEnabled(true);
                button3.setEnabled(false);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(10,17,48,22);
            }
            
            //--------------------------STOP BUTTON
            
            if(!IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(99,30,38,g);
                g.setColor(Color.red);
                MaestroG.fillCircle(97,28,38,g);
                g.setColor(Color.red.darker());
                MaestroG.drawCircle(97,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.red.darker());
                g.fillRect(74,17,48,22);
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(99,30,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(97,28,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(97,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(74,17,48,22);
            }

            //--------------------------RESET BUTTON
            
            if(IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(163,30,38,g);
                g.setColor(Color.yellow);
                MaestroG.fillCircle(161,28,38,g);
                g.setColor(Color.yellow.darker());
                MaestroG.drawCircle(161,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.yellow.darker());
                g.fillRect(138,17,48,22);
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(163,30,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(161,28,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(161,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(138,17,48,22);
            }
            
	}
	
	public void pause(boolean arg){
		clockcanvas.pause(arg);
	}
	
	public void start(){
		clockcanvas.start();
	}
	
	public void increment(){
		clockcanvas.increment();
	}
	
	public synchronized void setStatus(int CL_START, int CL_FINISH, int CL_DELTA){
		clockcanvas.setStatus(CL_START,CL_FINISH,CL_DELTA);
	}
	public synchronized void setSleepTime(int SleepTime){
		clockcanvas.setSleepTime(SleepTime);
	}
	public synchronized void reset(){
		clockcanvas.reset();
	}
	
}//End of StartStopClock.java
