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

public class OutPanel extends Canvas{
	private Image im;
	private Graphics buf;
	
	DipoleAnt ant;
	
	OutPanel(DipoleAnt ant){
		super();
		this.ant=ant;
		Color bgcolor = new Color(236,236,221);
		setBackground(bgcolor);

	}


/*public class OutPanel extends Panel{
	DipoleAnt ant;
	OutPanel(DipoleAnt ant){
		super();
		this.ant=ant;
		Color bgcolor = new Color(236,236,221);
		setBackground(bgcolor);
	}
*/	
	

	public void drawCanvas(Graphics g){
	//public void paint(Graphics g){
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                g.clearRect(0,0,getSize().width,getSize().height);
            
		int xshift = 10;
		g.setColor(Color.black);
		g.fillRect(0,0,getSize().width,getSize().height);	

		g.setColor(new Color(236,236,221));
		g.fillRect(1,1,getSize().width-2,getSize().height-2);	

		g.setFont(new Font("SanSerif",Font.BOLD,12));
		g.setColor(Color.red.darker());
		g.drawString("Output Data",5+xshift,20);
		g.setFont(new Font("SanSerif",Font.PLAIN,12));
		
                g.setColor(Color.blue.darker());
		if(ant.dipolelength != 0.0){
		    g.drawString("Radiated Power = "+ant.radiation_power+"",5+xshift,40);
		    g.drawString("[ W ]",240+xshift,40);
		    g.drawString("Radiation Resistance = "+ant.radiation_resistance+"",5+xshift,60);
		    
                    g.setFont(new Font("Serif",Font.PLAIN,14));
		    g.drawString("[ \u03a9 ]",240+xshift,60);
		    g.setFont(new Font("SanSerif",Font.PLAIN,12));

		}
		else{
		    g.drawString("Radiated Power = 0.0",5+xshift,40);
                    g.drawString("[ W ]",240+xshift,40);
		    g.drawString("Radiation Resistance = 0.0",5+xshift,60);
		    
                    g.setFont(new Font("Serif",Font.PLAIN,14));
		    g.drawString("[ \u03a9 ]",240+xshift,60);
		    g.setFont(new Font("Sanserif",Font.PLAIN,12));
		    
		}
		g.drawString("Directivity = "+ant.directivity,5+xshift,80);
	}

	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);
	    
	}
    
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}


	public void redraw(){
                repaint();
      }
	

	
}

