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

public class Timer extends Panel{
    private static final Color bgcolor = Color.white;
    public int CurrentTime, TotalTime;
    private Image im;
    private Graphics buf;

        
    public Timer(){
	super();
        setLayout(null);
	setBackground(bgcolor);
        
	CurrentTime = 0;
        TotalTime = 0;
    }
    
    public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawGraph(buf);
	    }
	    else{
		drawGraph(buf);
	    }
	    g.drawImage(im,0,0,null);
    }
	
	//Addition to reduce flicker new routine
    public void update(Graphics g){		// added to avoid clearing
	    paint(g);
    }
    
    public void drawGraph(Graphics g){
	g.setColor(bgcolor);	
	g.fillRect(0,0,getSize().width-1,getSize().height-1);  
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        g.setColor(Color.black);
        g.drawRect(0,0,getSize().width-1,getSize().height-1);
        
        double f_normalized;
        int x, xshift, y;
	x = 5;
        xshift = 140;
        y = 13;
        
        if(TotalTime <= 360){
            if(CurrentTime == 0){
                MaestroG.subscripterSansItalic21("t = ","0.0","T",g,12,x,y);
            }
            else if(CurrentTime <= 35 && CurrentTime > 0){
                MaestroG.subscripterSansItalic21("t = ","0.0"+(int)(MaestroA.rounder((double)CurrentTime/360.0,3)*1000),"T",g,12,x,y);
            }
            else if(CurrentTime < 360 && CurrentTime > 35){
                MaestroG.subscripterSansItalic21("t = ","0."+(int)(MaestroA.rounder((double)CurrentTime/360.0,3)*1000),"T ",g,12,x,y);
            }
            else{
                MaestroG.subscripterSansItalic21("t = ","1.0","T",g,12,x,y);
            }
        }
        if(TotalTime > 360){
            if(CurrentTime <= 35 && CurrentTime > 0){
                MaestroG.subscripterSansItalic21("t = ","0.0"+(int)(MaestroA.rounder((double)CurrentTime/360.0,3)*1000),"T + "+TotalTime/360+"T",g,12,x,y);
            }
            else if(CurrentTime < 360 && CurrentTime > 35){
                MaestroG.subscripterSansItalic21("t = ","0."+(int)(MaestroA.rounder((double)CurrentTime/360.0,3)*1000),"T + "+TotalTime/360+"T",g,12,x,y);
            }
            else{
                MaestroG.subscripterSansItalic21("t = ","0.0","T + "+TotalTime/360+"T",g,12,x,y);
            }
        }
        
        if(TotalTime < 360){  
            MaestroG.subscripterSansItalic22("\u03c9 t = ","",""+CurrentTime+"\u00ba","",g,12,x+xshift,y);
            
        }
        else if(TotalTime >= 360){
            if(CurrentTime == 360 || CurrentTime == 0){
                MaestroG.subscripterSansItalic22("\u03c9 t = ","","0\u00ba + "
                                                  +2*(TotalTime/360),"\u03c0",g,12,x+xshift,y);
            }
            else{
                MaestroG.subscripterSansItalic22("\u03c9 t = ","",""+CurrentTime+"\u00ba + "
                                                  +2*(TotalTime/360),"\u03c0",g,12,x+xshift,y);
            }
        }
        
    }
}