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


public class RadarCanvas extends Canvas{
	private Image im;
	private Graphics buf;

	Rectangle r;
	Antenna ant;
	
	private static final Color bgcolor = new Color(216,216,191);

	boolean is_theta_plane;
	RadarCanvas(Antenna ant, boolean is_theta_plane){
		super();
		this.ant=ant;
		this.is_theta_plane=is_theta_plane;
		
	}

	public void drawCanvas(Graphics g){
	//public void paint(Graphics g){
		Graphics2D g2d = (Graphics2D)g;
                
                int i;
		double theta, phi;
		
		double geom;
		
		r=getBounds();	
		g.setColor(Color.lightGray);
		//g.setColor(bgcolor);
		g.fill3DRect(0,0,r.width-1,r.height-1,true);
	
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(Color.white);
		//draw concentric circles
		g.drawOval((int)(r.width*0.4),(int)(r.width*0.4),(int)(r.width*0.20),(int)(r.width*0.20));
		g.drawOval((int)(r.width*0.3),(int)(r.width*0.3),(int)(r.width*0.40),(int)(r.width*0.40));
		g.drawOval((int)(r.width*0.2),(int)(r.width*0.2),(int)(r.width*0.60),(int)(r.width*0.60));
		g.drawOval((int)(r.width*0.1),(int)(r.width*0.1),(int)(r.width*0.80),(int)(r.width*0.80));

		//draw radial lines
		g.drawLine((int)(r.width*0.1),(int)(r.width*0.5),(int)(r.width*0.9),(int)(r.width*0.5));
		g.drawLine((int)(r.width*0.5),(int)(r.width*0.1),(int)(r.width*0.5),(int)(r.width*0.9));
		g.drawLine( (int)(r.width*(0.5+0.4*(0.866))), (int)(r.width*(0.5+0.4*(0.5))), 
                            (int)(r.width*(0.5-0.4*(0.866))), (int)(r.width*(0.5-0.4*(0.5))));
		g.drawLine( (int)(r.width*(0.5-0.4*(0.866))), (int)(r.width*(0.5+0.4*(0.5))), 
                            (int)(r.width*(0.5+0.4*(0.866))), (int)(r.width*(0.5-0.4*(0.5))));
		g.drawLine( (int)(r.width*(0.5+0.4*(0.5))), (int)(r.width*(0.5+0.4*(0.866))), 
                            (int)(r.width*(0.5-0.4*(0.5))), (int)(r.width*(0.5-0.4*(0.866))));
		g.drawLine( (int)(r.width*(0.5-0.4*(0.5))), (int)(r.width*(0.5+0.4*(0.866))), 
                            (int)(r.width*(0.5+0.4*(0.5))), (int)(r.width*(0.5-0.4*(0.866))));
		
                //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                
		g.setColor(Color.black);
		//write the angles
		if(this.is_theta_plane==true)
		{	g.setColor(Color.red.darker());
			g.setFont(new Font("Serif",Font.PLAIN,18));
			g.drawString("\u03b8",20,20);
			
			g.setColor(Color.blue);
			g.setFont(new Font("Serif",Font.PLAIN,13));
			g.drawString("\u03c6 = "+(int)(ant.phicontrol.phi)+"\u00ba",r.width-50,20);
			
			g.setColor(Color.black);
			g.setFont(new Font("Sanserif",Font.PLAIN,11));
			g.drawString("0\u00ba",(int)(r.width*  (0.5-0.42*(0.030))),(int)(r.width*(0.5+0.42*(-1.00))));
			g.drawString("30\u00ba",(int)(r.width* (0.5+0.42*(0.500))),(int)(r.width*(0.5+0.44*(-0.866))));
			g.drawString("30\u00ba",(int)(r.width* (0.5-0.44*(0.500))-3),(int)(r.width*(0.5+0.44*(-0.866))));
			g.drawString("60\u00ba",(int)(r.width* (0.5+0.42*(0.9))),(int)(r.width*(0.5+0.44*(-0.50))));
			g.drawString("60\u00ba",(int)(3+r.width* (0.5-0.44*(1.0))),(int)(r.width*(0.5+0.44*(-0.50))));
			g.drawString("90\u00ba",(int)(r.width* (0.5+0.42*(1.000))),(int)(r.width*(0.5+0.30*(0.05))));
			g.drawString("90\u00ba",(int)(3+r.width* (0.5-0.46*(1.050))),(int)(r.width*(0.5+0.30*(0.05))));
			g.drawString("120\u00ba",(int)(r.width*(0.5+0.43*(0.866))),(int)(r.width*(0.5+0.48*(0.50))));
			g.drawString("120\u00ba",(int)(3+r.width*(0.5-0.48*(0.95))),(int)(r.width*(0.5+0.48*(0.50))));
			g.drawString("150\u00ba",(int)(r.width*(0.5+0.42*(0.450))),(int)(r.width*(0.5+0.47*(0.866))));
			g.drawString("150\u00ba",(int)(r.width*(0.5-0.47*(0.550))),(int)(r.width*(0.5+0.47*(0.866))));
			g.drawString("180\u00ba",(int)(r.width*(0.5-0.42*(0.070))),(int)(r.width*(0.5+0.44*(1.05))));
		}
		else{   g.setColor(Color.red.darker());
			g.setFont(new Font("Serif",Font.PLAIN,18));
			g.drawString("\u03c6",20,20);
			
			g.setColor(Color.blue);
			g.setFont(new Font("Serif",Font.PLAIN,13));
			g.drawString("\u03b8 = 90\u00ba",r.width-45,20);
			
			g.setFont(new Font("Sanserif",Font.PLAIN,11));
			g.setColor(Color.black);
			g.drawString("180\u00ba",(int)(r.width*  (0.5-0.43*(0.055))),(int)(r.width*(0.5+0.42*(-1.00))));
			g.drawString("150\u00ba",(int)(r.width* (0.5+0.42*(0.4500))),(int)(r.width*(0.5+0.42*(-0.866))));
			g.drawString("210\u00ba",(int)(r.width* (0.5-0.47*(0.550))),(int)(r.width*(0.5+0.42*(-0.866))));
			g.drawString("120\u00ba",(int)(r.width* (0.5+0.42*(0.866))),(int)(r.width*(0.5+0.42*(-0.50))));
			g.drawString("240\u00ba",(int)(r.width* (0.5-0.44*(1.0))),(int)(r.width*(0.5+0.42*(-0.50))));
			g.drawString("90\u00ba",(int)(3+r.width* (0.5+0.42*(1.000))),(int)(r.width*(0.5+0.30*(0.05))));
			g.drawString("270\u00ba",3+(int)(3+r.width* (0.5-0.46*(1.120))),(int)(r.width*(0.5+0.30*(0.05))));
			g.drawString("60\u00ba",(int)(r.width*(0.5+0.43*(0.866))),(int)(r.width*(0.5+0.48*(0.50))));
			g.drawString("300\u00ba",(int)(r.width* (0.5-0.44*(1.0))),(int)(r.width*(0.5+0.48*(0.50))));
			g.drawString("30\u00ba",4+(int)(r.width*(0.5+0.42*(0.450))),(int)(r.width*(0.5+0.47*(0.866))));
			g.drawString("330\u00ba",(int)(r.width*(0.5-0.47*(0.550))),(int)(r.width*(0.5+0.47*(0.866))));
			g.drawString("0\u00ba",(int)(r.width*(0.5-0.2*(0.030))),(int)(r.width*(0.5+0.44*(1.05))));
		}
		if(this.is_theta_plane==true){//This is the theta plane
		//draw two dipole antennae 
/*		  g.setColor(Color.red);
		  g.drawLine((int)(r.width*(0.42)),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.42)),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.42)),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.42)),(int)(r.width*(0.5+0.01)));

		  g.setColor(Color.green);
		  g.drawLine((int)(r.width*(0.58)),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.58)),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.58)),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.58)),(int)(r.width*(0.5+0.01)));
*/

		//draw angle label
		/*Image thetaimage;
		thetaimage=ant.getImage(ant.getDocumentBase(),"theta.gif");
		g.drawImage(thetaimage,r.width-20,r.width-20,this);
		*/

		}
		else{//This is phi plane
		  

			// Draw cross-section line 
                  
                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		  g.setColor(Color.yellow);
		  g.drawArc((int)(r.width/2.0*(1.0-0.82)),(int)(r.width/2.0*(1.0-0.82)),(int)(r.width*0.825),(int)(r.width*0.825),-90,(int)(ant.phicontrol.phi));
		  g.setColor(Color.black);
		  g.drawArc((int)(r.width/2.0*(1.0-0.82))-1,(int)(r.width/2.0*(1.0-0.82))-1,(int)(r.width*0.825)+2,(int)(r.width*0.825)+2,-90,(int)(ant.phicontrol.phi));
		  
                  //g.drawArc((int)(r.width*0.1),(int)(r.width*0.1),(int)(r.width*0.80),(int)(r.width*0.80), -90,(int)(ant.phicontrol.phi));
		  
		  g.setColor(Color.yellow);
		  g.drawLine((int)((r.width/2.0)*(1.0+0.82*Math.cos((ant.phicontrol.phi-90)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0-0.82*Math.sin((ant.phicontrol.phi-90)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0-0.8*Math.cos((ant.phicontrol.phi-90)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0+0.8*Math.sin((ant.phicontrol.phi-90)*Math.PI/180.0))));

			// Draw Antennas - view from top

		  g.setColor(Color.red);
		  g.fillOval(
			(int)(r.width*(0.34)-r.width*(0.00625)),
			(int)(r.width*(0.5)-r.width*(0.00625)),
			(int)(r.width*(0.025)),
			(int)(r.width*(0.025)));
		  g.setColor(Color.black);
		  g.drawOval(
			(int)(r.width*(0.34)-r.width*(0.00625)),
			(int)(r.width*(0.5)-r.width*(0.00625)),
			(int)(r.width*(0.025)),
			(int)(r.width*(0.025)));

		  g.setColor(Color.green);
		  g.fillOval(
			(int)(r.width*(0.66)-r.width*(0.00625)),
			(int)(r.width*(0.5)-r.width*(0.00625)),
			(int)(r.width*(0.025)),
			(int)(r.width*(0.025)));
		  g.setColor(Color.black);
		  g.drawOval(
			(int)(r.width*(0.66)-r.width*(0.00625)),
			(int)(r.width*(0.5)-r.width*(0.00625)),
			(int)(r.width*(0.025)),
			(int)(r.width*(0.025)));
			//Draw view-angle arrow
			
		//Draw view-angle arrow

		  //g.setColor(Color.white);
		  g.setColor(Color.black);
		  g.drawLine((int)((r.width/2.0)*(1.0+0.63*Math.cos((ant.phicontrol.phi-180.0)*Math.PI/180.0))),
		  	     (int)((r.width/2.0)*(1.0-0.63*Math.sin((ant.phicontrol.phi-180.0)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0+0.815*Math.cos((ant.phicontrol.phi-180.0)*Math.PI/180.0))),
		  	     (int)((r.width/2.0)*(1.0-0.815*Math.sin((ant.phicontrol.phi-180.0)*Math.PI/180.0)))
			    );
		  
		  g.setColor(Color.yellow);
		 
		  Polygon s = new Polygon();
		  s.addPoint((int)((r.width/2.0)*(1.0+0.63*Math.cos((ant.phicontrol.phi-180.0)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0-0.63*Math.sin((ant.phicontrol.phi-180.0)*Math.PI/180.0))));
		  s.addPoint((int)((r.width/2.0)*(1.0+0.72*Math.cos((ant.phicontrol.phi-184.0)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0-0.72*Math.sin((ant.phicontrol.phi-184.0)*Math.PI/180.0))));
		  s.addPoint((int)((r.width/2.0)*(1.0+0.72*Math.cos((ant.phicontrol.phi-176.0)*Math.PI/180.0))),
			     (int)((r.width/2.0)*(1.0-0.72*Math.sin((ant.phicontrol.phi-176.0)*Math.PI/180.0))));

		  g.fillPolygon(s);
		  g.setColor(Color.black);
		  g.drawPolygon(s);
		}
                                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
		
                
                //Now draw the radiation diagram
		g.setColor(Color.blue);
		//g.setColor(Color.black);
       if(this.is_theta_plane==true){
		//draw two dipole antennae 
		  geom = (r.width*0.16*Math.cos((ant.phicontrol.phi-90.0)*Math.PI/180));
		
                  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		  
                  g.setColor(Color.red);
		  g.drawLine((int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom),(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5+0.01)));
		  g.setColor(Color.black);
		  g.drawLine((int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5+0.1)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5-0.01)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5-0.01)));

		  g.setColor(Color.green);
		  g.drawLine((int)(r.width*(0.5)+geom+1),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)+geom+1),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom+1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)+geom+1),(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)+geom),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)+geom),(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom-1),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)+geom-1),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom-1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)+geom-1),(int)(r.width*(0.5+0.01)));
		  g.setColor(Color.black);
		  g.drawLine((int)(r.width*(0.5)+geom+1)+1,(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)+geom+1)+1,(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom+1)+1,(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)+geom+1)+1,(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)+geom-1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)+geom+1)+1,(int)(r.width*(0.5+0.1)));
		  g.drawLine((int)(r.width*(0.5)+geom-1),(int)(r.width*(0.5-0.01)),
		           (int)(r.width*(0.5)+geom+1)+1,(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5-0.01)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5-0.01)));

		if((ant.phicontrol.phi<4) || (ant.phicontrol.phi>=268+90)){//&&ant.phicontrol.phi<=272){
		
		  g.setColor(Color.red);
		  g.drawLine((int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom),(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5+0.01)));
		  g.setColor(Color.black);
		  g.drawLine((int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5+0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5-0.1)),
		           (int)(r.width*(0.5)-geom+1)+1,(int)(r.width*(0.5-0.01)));
		  g.drawLine((int)(r.width*(0.5)-geom-1),(int)(r.width*(0.5+0.1)),
		           (int)(r.width*(0.5)-geom+1),(int)(r.width*(0.5+0.1)));

			// drawing of antennae finished
		}
			//Now draw radiation patterns
		 g.setColor(Color.blue);
		 //g.setColor(Color.black);
		
                 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                 
                 if(ant.rcons.c1.getState()==true){
			for(i=0;i<360;i++){		
				theta=(2.0*Math.PI*i/360.0f-Math.PI/2.0);
				 g.drawLine(
					//(int)(r.width*(0.5+0.4*ant.efield[i].Magnitude()*Math.cos(theta))),
					//(int)(r.width*(0.5+0.4*ant.efield[i].Magnitude()*Math.sin(theta))),
					//(int)(r.width*(0.5+0.4*ant.efield[i+1].Magnitude()*Math.cos(theta))),
					//(int)(r.width*(0.5+0.4*ant.efield[i+1].Magnitude()*Math.sin(theta))));
					
					(int)(r.width*(0.5+0.4*ant.efield_mag[i]*Math.cos(theta))),
					(int)(r.width*(0.5+0.4*ant.efield_mag[i]*Math.sin(theta))),
					(int)(r.width*(0.5+0.4*ant.efield_mag[i+1]*Math.cos(theta))),
					(int)(r.width*(0.5+0.4*ant.efield_mag[i+1]*Math.sin(theta))));
				
			}
		}
		
		if(ant.rcons.c3.getState()==true){
			for(i=0;i<360;i++){		
				theta=(2.0*Math.PI*i/360.0f-Math.PI/2.0);
				g.drawLine(
					(int)(r.width*(0.5+0.4*ant.power[i]*Math.cos(theta))),
					(int)(r.width*(0.5+0.4*ant.power[i]*Math.sin(theta))),
					(int)(r.width*(0.5+0.4*ant.power[i+1]*Math.cos(theta))),
					(int)(r.width*(0.5+0.4*ant.power[i+1]*Math.sin(theta))));
				
			}
		}
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	    }
            else{
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		if(ant.rcons.c1.getState()==true){
			for(i=0;i<360;i++){		
				phi=(2.0*Math.PI*i/360.0f);
				 g.drawLine(
					//(int)(r.width*(0.5+0.4*ant.eefield[i].Magnitude()*Math.cos(phi))),
					//(int)(r.width*(0.5+0.4*ant.eefield[i].Magnitude()*Math.sin(phi))),
					//(int)(r.width*(0.5+0.4*ant.eefield[i+1].Magnitude()*Math.cos(phi))),
					//(int)(r.width*(0.5+0.4*ant.eefield[i+1].Magnitude()*Math.sin(phi))));
					
					(int)(r.width*(0.5+0.4*ant.eefield_mag[i]*Math.cos(phi))),
					(int)(r.width*(0.5+0.4*ant.eefield_mag[i]*Math.sin(phi))),
					(int)(r.width*(0.5+0.4*ant.eefield_mag[i+1]*Math.cos(phi))),
					(int)(r.width*(0.5+0.4*ant.eefield_mag[i+1]*Math.sin(phi))));
				 
			}
		}
		if(ant.rcons.c3.getState()==true){
			for(i=0;i<360;i++){		
				phi=(2.0*Math.PI*i/360.0f);
				g.drawLine(
					(int)(r.width*(0.5+0.4*ant.ppower[i]*Math.cos(phi))),
					(int)(r.width*(0.5+0.4*ant.ppower[i]*Math.sin(phi))),
					(int)(r.width*(0.5+0.4*ant.ppower[i+1]*Math.cos(phi))),
					(int)(r.width*(0.5+0.4*ant.ppower[i+1]*Math.sin(phi))));
				
			}
		}
            
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	    }
	    
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	    
	    //drawCanvas(g);
	}
    
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}


	
	public void redraw(){
                repaint();
        }
}//End of RadarCanvas
