//PlaneWaveOutputPanel.java
import java.awt.*;
import java.awt.event.*;

public class PlaneWaveOutputPanel extends Panel implements ItemListener{
	private static final Color bgcolor = new Color(236,236,236);
	private Font labfont;
	private Font symbolfont;
        private Font titlefont;
        
	Label titlelabel;	
	public Choice c1;
	public PlaneWaveOutputCanvasA pwocA; 
	public PlaneWaveOutputCanvasB pwocB; 
	
        PlaneWave_State state;
        
        public PlaneWaveOutputPanel(PlaneWave_State state){
	    super();
	    setLayout(null);
            this.state = state;
	    
            setBackground(bgcolor);
            labfont=new Font("SanSerif",Font.PLAIN,state.s11);
            symbolfont=new Font("Serif",Font.PLAIN,state.s12);
            titlefont=new Font("SanSerif",Font.BOLD,16);
	
	    titlelabel = new Label("Output Data");
	    titlelabel.setFont(titlefont);
	    
	    c1 = new Choice();
	    c1.addItem("   Wave Properties   ");
	    c1.addItem("   Power Flow   ");
	    //add(c1);
	    c1.setBounds(state.s120,state.s5,state.s150,state.s30);
	    
	    pwocA = new PlaneWaveOutputCanvasA(state);
	    add(pwocA);
	    pwocA.setBounds(state.s5,0,state.s200+state.s80,state.s200+state.s65);
	    pwocB = new PlaneWaveOutputCanvasB(state);
	    add(pwocB);
	    pwocB.setBounds(state.s5,0,state.s200+state.s80,state.s200+state.s55);
	    
	    pwocA.setVisible(true);
	    pwocB.setVisible(false);
	    //Listeners
	    c1.addItemListener(this);
	}

    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]=="   Wave Properties   "){
		    pwocA.setVisible(true);
		    pwocB.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="   Power Flow   "){
		    pwocA.setVisible(false);
		    pwocB.setVisible(true);
		}
	    }
        }	
    }//PlaneWaveOutputPanel.java

    class PlaneWaveOutputCanvasA extends Canvas{
	private Font normalfont;
	private Font symbolfont;
	private Font subfont;
	
        PlaneWave_State state;
	private Image im;
	private Graphics buf;

	public PlaneWaveOutputCanvasA(PlaneWave_State state){
	    super();
	    this.state = state;
	}
	
	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){
            normalfont = new Font("SanSerif",Font.PLAIN,state.font11);
            symbolfont = new Font("Serif",Font.PLAIN,state.font14);
            subfont    = new Font("SanSerif",Font.PLAIN,state.font10);
            
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized;
	    FontMetrics fm;
	    double temp, temp2;
	    int fonto = state.font11;
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            x = state.s20;
	    y = state.s43;
	    dx = state.s85;
	    dxx = state.s15;
            
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight() + state.s5;
	    dyy = dy + state.s5;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    g.setColor(Color.red.darker());
	    g.drawString("WaveLength",x,y);
	    
            int startx = state.s15;
            //g.setColor(Color.gray);
            //MaestroG.subscripterBold("Output","","",g,state.font14,startx+state.s1,startx+state.s6);
            g.setColor(Color.red.darker());
            MaestroG.subscripterBold("Output","","",g,state.font14,startx,startx+state.s5);
            
            g.setColor(Color.black);
	    temp2 = state.wavelength;
	    g.setFont(symbolfont);
	    g.drawString("\u03bb",x+dx,y);
	    g.setFont(normalfont);	
            
            if(state.frequency == 0.0){		
                g.drawString("  =        [ m ]",x+dx+state.s10,y);
                g.setFont(symbolfont);
                g.drawString("\u221e",x+dx+fm.stringWidth("  =   "),y);
                g.setFont(normalfont);
            }
            else if(temp2 >= 1.0E15 && state.frequency > 0.0){
                temp = temp2;
                MaestroG.superscripter("  =  "+temp+"   [ m ]","","",g,fonto,x+dx+state.s10,y); 
            }
            else if(temp2 < 1.0e15 && temp2 >= 1.0E12){
                temp = temp2/1.0E12;
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","9"," km ]",g,fonto,x+dx+state.s10,y);  
            }
            else if(temp2 < 1.0e12 && temp2 >= 1.0e9){
                temp = temp2/1.0E9;
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","6"," km ]",g,fonto,x+dx+state.s10,y);   
            }
            else if(temp2 < 1.0e9 && temp2 >= 1.0e6){
                temp = temp2/1.0E6; 
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","3"," km ]",g,fonto,x+dx+state.s10,y);  
            }
            else if(temp2 < 1.0E6 && temp2 >= 1.0E3){
                temp = temp2/1.0E3;
                g.drawString("  =  "+MaestroA.rounder(temp,5)+"   [ km ]",x+dx+state.s10,y);
            }
            else if(temp2 < 1.0E3 && temp2 >= 1.0){
                g.drawString("  =  "+MaestroA.rounder(temp2,5)+"   [ m ]",x+dx+state.s10,y);
            }
            else if(temp2 <1.0 && temp2 >= 1.0E-2){
                temp = temp2*1.0E2;
                g.drawString("  =  "+MaestroA.rounder(temp,5)+"   [ cm ]",x+dx+state.s10,y);
            }
            else if(temp2 <1.0E-2 && temp2 >= 1.0E-4){
                temp = temp2*1.0E3;
                g.drawString("  =  "+MaestroA.rounder(temp,5)+"   [ mm ]",x+dx+state.s10,y);
            }
            else if(temp2 < 1.0E-4 && temp2 >=1.0E-6 ){
                temp = temp2*1.0E6;
                g.drawString("  =  "+MaestroA.rounder(temp,5)+"   [ \u00b5 m ]",x+dx+state.s10,y);
            }
            else if(temp2 < 1.0E-6 && temp2 >=1.0E-9){
                temp = temp2*1.0E9;
                g.drawString("  =  "+MaestroA.rounder(temp,5)+"   [ nm ]",x+dx+state.s10,y);
            }	
            else if(temp2 < 1.0E-9 && temp2 >=1.0E-12){
                temp = temp2*1.0E12;
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","-12","  m ]",g,fonto,x+dx+state.s10,y);
            }	   
            else if(temp2 < 1.0E-12 && temp2 >=1.0E-15){
                temp = temp2*1.0E15;
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","-15","  m ]",g,fonto,x+dx+state.s10,y);
            }
            else if(temp2 < 1.0E-15 && temp2 >=1.0e-18){
                temp = temp2*1.0E18;
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","-18","  m ]",g,fonto,x+dx+state.s10,y);
            }
            else if(temp2 < 1.0E-18 && temp2 >=1.0E-21){
                temp = temp2*1.0E21;
                MaestroG.superscripter("  =  "+MaestroA.rounder(temp,5)+"   [ 10","-21","  m ]",g,fonto,x+dx+state.s10,y);
            }
            else if(temp2 < 1.0E-21 && temp2 > 0.0){
                temp = temp2;
                MaestroG.superscripter("  =  "+temp+" [m]","","",g,fonto,x+dx+state.s10,y);  
            }
            else if(temp2 == 0.0){
                g.drawString("  =  "+MaestroA.rounder(temp2,8)+"   [ m ]",x+dx+state.s10,y); 
            }   

	    y += dyy;
	    g.setColor(Color.red.darker());
	    g.drawString("Phase Velocity",x,y);
	    g.setColor(Color.black);
	    
	    if(state.phase_velocity >= 1.0e8){
		v_normalized = state.phase_velocity/1.0E8;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","8"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e7 && state.phase_velocity < 1.0e8){
		v_normalized = state.phase_velocity/1.0E7;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","7"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e6 && state.phase_velocity < 1.0e7){
		v_normalized = state.phase_velocity/1.0E6;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","6"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e5 && state.phase_velocity < 1.0e6){
		v_normalized = state.phase_velocity/1.0E5;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","5"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e4 && state.phase_velocity < 1.0e5){
		v_normalized = state.phase_velocity/1.0E4;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","4"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e3 && state.phase_velocity < 1.0e4){
		v_normalized = state.phase_velocity/1.0E3;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","3"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e2 && state.phase_velocity < 1.0e3){
		v_normalized = state.phase_velocity/1.0E2;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","2"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    //else if(state.phase_velocity >= 1.0e1 && state.phase_velocity < 1.0e2){
		//v_normalized = state.phase_velocity/10.0;
		//MaestroG.subsupspecial("v","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10",""," [ m / s ]",g,fonto,x+dx,y);
		////g.drawString("Vp  =  "+MaestroA.rounder(v_normalized,5)+"   [ 1.0 E+1  m / s ]",x+dxx,y);
	    //}
	    else if(state.phase_velocity >= 1.0 && state.phase_velocity < 1.0e2){
		v_normalized = state.phase_velocity;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+"",""," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-1 && state.phase_velocity < 1.0){
		v_normalized = state.phase_velocity*10.0;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-1"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-2 && state.phase_velocity < 1.0e-1){
		v_normalized = state.phase_velocity*1.0e2;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-2"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-3 && state.phase_velocity < 1.0e-2){
		v_normalized = state.phase_velocity*1.0e3;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-3"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-4 && state.phase_velocity < 1.0e-3){
		v_normalized = state.phase_velocity*1.0e4;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-4"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-5 && state.phase_velocity < 1.0e-4){
		v_normalized = state.phase_velocity*1.0e5;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-5"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-6 && state.phase_velocity < 1.0e-5){
		v_normalized = state.phase_velocity*1.0e6;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-6"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-7 && state.phase_velocity < 1.0e-6){
		v_normalized = state.phase_velocity*1.0e7;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-7"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-8 && state.phase_velocity < 1.0e-7){
		v_normalized = state.phase_velocity*1.0e8;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-8"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity >= 1.0e-9 && state.phase_velocity < 1.0e-8){
		v_normalized = state.phase_velocity*1.0e9;
		MaestroG.subsupspecial("u","p","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-9"," [ m / s ]",g,fonto,x+dx,y);
	    }
	    else if(state.phase_velocity < 1.0e-9){
		v_normalized = state.phase_velocity*1.0e10;
		MaestroG.subsupspecial("u","p","  =  "+v_normalized+" x 10","-10"," [ m / s ]",g,fonto,x+dx,y);
	    }
            //----------------------------------------- Period
            dx = dx + state.s3;
            y += dyy + state.s2;
	    g.setColor(Color.red.darker());
	    g.drawString("Period",x,y);
	    g.setColor(Color.black);
	    
	    if(state.period >= 1.0e8){
		v_normalized = state.period/1.0E8;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","8"," [ s ]",g,fonto,x+dx,y);	
	    }
	    else if(state.period >= 1.0e7 && state.period < 1.0e8){
		v_normalized = state.period/1.0E7;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","7"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e6 && state.period < 1.0e7){
		v_normalized = state.period/1.0E6;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","6"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e5 && state.period < 1.0e6){
		v_normalized = state.period/1.0E5;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","5"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e4 && state.period < 1.0e5){
		v_normalized = state.period/1.0E4;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","4"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e3 && state.period < 1.0e4){
		v_normalized = state.period/1.0E3;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","3"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e2 && state.period < 1.0e3){
		v_normalized = state.period/1.0E2;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","2"," [ s ]",g,fonto,x+dx,y);
	    }
	    //else if(state.period >= 1.0e1 && state.period < 1.0e2){
		//v_normalized = state.period/10.0;
		//MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10",""," [ s ]",g,fonto,x+dx,y);
	    //}
	    else if(state.period >= 1.0 && state.period < 1.0e2){
		v_normalized = state.period;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+"",""," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-1 && state.period < 1.0){
		v_normalized = state.period*10.0;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-1"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-2 && state.period < 1.0e-1){
		v_normalized = state.period*1.0e2;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-2"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-3 && state.period < 1.0e-2){
		v_normalized = state.period*1.0e3;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-3"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-4 && state.period < 1.0e-3){
		v_normalized = state.period*1.0e4;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-4"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-5 && state.period < 1.0e-4){
		v_normalized = state.period*1.0e5;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-5"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-6 && state.period < 1.0e-5){
		v_normalized = state.period*1.0e6;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-6"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-7 && state.period < 1.0e-6){
		v_normalized = state.period*1.0e7;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-7"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-8 && state.period < 1.0e-7){
		v_normalized = state.period*1.0e8;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-8"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-9 && state.period < 1.0e-8){
		v_normalized = state.period*1.0e9;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-9"," [ s ]",g,fonto,x+dx,y);
	    }
	    else if(state.period >= 1.0e-10 && state.period < 1.0e-9){
		v_normalized = state.period*1.0e10;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-10"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-11 && state.period < 1.0e-10){
		v_normalized = state.period*1.0e11;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-11"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-12 && state.period < 1.0e-11){
		v_normalized = state.period*1.0e12;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-12"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-13 && state.period < 1.0e-12){
		v_normalized = state.period*1.0e13;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-13"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-14 && state.period < 1.0e-13){
		v_normalized = state.period*1.0e14;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-14"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-15 && state.period < 1.0e-14){
		v_normalized = state.period*1.0e15;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-15"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-16 && state.period < 1.0e-15){
		v_normalized = state.period*1.0e16;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-16"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-17 && state.period < 1.0e-16){
		v_normalized = state.period*1.0e17;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-17"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-18 && state.period < 1.0e-17){
		v_normalized = state.period*1.0e18;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-18"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-19 && state.period < 1.0e-18){
		v_normalized = state.period*1.0e19;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-19"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-20 && state.period < 1.0e-19){
		v_normalized = state.period*1.0e20;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-20"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-21 && state.period < 1.0e-20){
		v_normalized = state.period*1.0e21;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-21"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-22 && state.period < 1.0e-21){
		v_normalized = state.period*1.0e22;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-22"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-23 && state.period < 1.0e-22){
		v_normalized = state.period*1.0e23;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-23"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period >= 1.0e-24 && state.period < 1.0e-23){
		v_normalized = state.period*1.0e24;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-24"," [ s ]",g,fonto,x+dx,y);
	    }
            else if(state.period < 1.0e-24){
		v_normalized = state.period*1.0e25;
		MaestroG.subsupspecial2("T","","  =  "+MaestroA.rounder(v_normalized,5)+" x 10","-25"," [ s ]",g,fonto,x+dx,y);
	    }
            //------------------------------------------------
            dx = dx - state.s3;
	    //g.drawLine(5,y,getSize().width-5,y); 
	    g.setColor(Color.red.darker());
	    y += dyy;
	    g.drawString("Impedance of the Medium  [     ]", x, y);
	    g.setFont(symbolfont);
	    g.drawString("\u03a9",x+fm.stringWidth("Impedance of the Medium  [ "),y);
	    g.setFont(normalfont);	
	    y+= dy;
	    g.setColor(Color.black);
	    
	    g.setFont(symbolfont);
	    g.drawString("\u03b7",x+dxx,y);
	    g.setFont(normalfont);	
            //----------------------------------------------------------------------------------
            int xinit2, xinit3, stepx;
            double tempR, tempX;

            String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, 
                   sign, plusr, minusr, signr;

            plusj =" + j ";
            minusj=" - j ";
            plusr ="";
            minusr =" - ";

            xinit2 = x+dxx + state.s10;

            tempR=0.0; tempX=0.0;
            stepx = 0;

            if(Complex.Imaginary(state.wave_impedance) >= 0.0){sign = plusj;}
            else{sign = minusj;}

            tempR = state.wave_impedance.Real();

            if(tempR < 1.0E3 && tempR >= 1.0E-3){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR,6),"","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR,6));
            }
            else if(tempR == 0.0){
                MaestroG.superscripter("  = 0.0","","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = 0.0 ");
            }
            else if(tempR < 1.0E6 && tempR >= 1.0E3){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
            }
            else if(tempR < 1.0E9 && tempR >= 1.0E6){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
            }
            else if(tempR < 1.0E12 && tempR >= 1.0E9){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
            }
            else if(tempR < 1.0E15 && tempR >= 1.0E12){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
            }
            else if(tempR < 1.0E18 && tempR >= 1.0E15){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
            }
            else if(tempR < 1.0E21 && tempR >= 1.0E18){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
            }
            else if(tempR < 1.0E24 && tempR >= 1.0E21){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
            }
            else if(tempR < 1.0E27 && tempR >= 1.0E24){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
            }
            else if(tempR < 1.0E30 && tempR >= 1.0E27){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
            }
            else if(tempR >= 1.0E30){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
            }
            else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
            }
            else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
            }
            else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
            }
            else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
            }
            else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
            }
            else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
            }
            else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
            }
            else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
            }
            else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
                MaestroG.superscripter("  = "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
            }
            else if(tempR < 1.0E-30 && tempR != 0.0){
                MaestroG.superscripter("  = 0.0","","",g,fonto,xinit2,y);
                stepx = fm.stringWidth("  = 0.0");
            }            
	    //g.drawLine(5,y,getSize().width-5,y); 
	    y += dyy;
	    g.setColor(Color.red.darker());
	    MaestroG.superscripter("Phase Constant  [ m","-1"," ]",g,fonto,x,y);
            //g.drawString("Phase Constant",x,y);
	    y += dy;
	    g.setColor(Color.black);
            //MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x+dxx+state.s150,y);
	    
	    if(state.beta < 1.0e-15){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e16,5)+"  x  10","-16"," ",g,fonto,xinit2,y);
	    }
            if(state.beta >= 1.0e-15 && state.beta < 1.0e-14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e15,5)+"  x  10","-15"," ",g,fonto,xinit2,y);
	    }
            if(state.beta >= 1.0e-14 && state.beta < 1.0e-13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e14,5)+"  x  10","-14"," ",g,fonto,xinit2,y);
	    }
            if(state.beta >= 1.0e-13 && state.beta < 1.0e-12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e13,5)+"  x  10","-13"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-12 && state.beta < 1.0e-11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e12,5)+"  x  10","-12"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-11 && state.beta < 1.0e-10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e11,5)+"  x  10","-11"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-10 && state.beta < 1.0e-9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e10,5)+"  x  10","-10"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-9 && state.beta < 1.0e-8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e9,5)+"  x  10","-9"," ",g,fonto,xinit2,y);
	    }
	    
	    if(state.beta >= 1.0e-8 && state.beta < 1.0e-7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e8,5)+"  x  10","-8"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-7 && state.beta < 1.0e-6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e7,5)+"  x  10","-7"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-6 && state.beta < 1.0e-5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e6,5)+"  x  10","-6"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-5 && state.beta < 1.0e-4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e5,5)+"  x  10","-5"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-4 && state.beta < 1.0e-3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e4,5)+"  x  10","-4"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-3 && state.beta < 1.0e-2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e3,5)+"  x  10","-3"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-2 && state.beta < 1.0e-1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e2,5)+"  x  10","-2"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e-1 && state.beta < 1.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e1,5)+"  x  10","-1"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0 && state.beta < 1.0e1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta,5)+"  ",""," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e1 && state.beta < 1.0e2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta,5)+"  ",""," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e2 && state.beta < 1.0e3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-2,5)+"  x  10","2"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e3 && state.beta < 1.0e4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-3,5)+"  x  10","3"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e4 && state.beta < 1.0e5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-4,5)+"  x  10","4"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e5 && state.beta < 1.0e6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-5,5)+"  x  10","5"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e6 && state.beta < 1.0e7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-6,5)+"  x  10","6"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e7 && state.beta < 1.0e8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-7,5)+"  x  10","7"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e8 && state.beta < 1.0e9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-8,5)+"  x  10","8"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e9 && state.beta < 1.0e10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-9,5)+"  x  10","9"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e10 && state.beta < 1.0e11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-10,5)+"  x  10","10"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e11 && state.beta < 1.0e12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-11,5)+"  x  10","11"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e12 && state.beta < 1.0e13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-12,5)+"  x  10","12"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e13 && state.beta < 1.0e14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-13,5)+"  x  10","13"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e14 && state.beta < 1.0e15){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-14,5)+"  x  10","14"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e15 && state.beta < 1.0e16){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-15,5)+"  x  10","15"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e16 && state.beta < 1.0e17){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-16,5)+"  x  10","16"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e17 && state.beta < 1.0e18){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-17,5)+"  x  10","17"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e18 && state.beta < 1.0e19){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-18,5)+"  x  10","18"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e19 && state.beta < 1.0e20){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-19,5)+"  x  10","19"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e20 && state.beta < 1.0e21){
		MaestroG.superscripter("  =  "+MaestroA.rounder(state.beta*1.0e-20,5)+"  x  10","20"," ",g,fonto,xinit2,y);
	    }
	    if(state.beta >= 1.0e21){
		MaestroG.superscripter("  =  "+state.beta+"",""," ",g,fonto,xinit2,y);
	    }
	    g.setFont(symbolfont);
	    g.drawString("\u03b2",x+dxx,y);
	    g.setFont(normalfont);
            
            y+=dyy;
            y+=dy;
            
            if(state.IsLinear){
                g.setColor(Color.black);
                MaestroG.subscripter("LINEAR POLARIZATION","","",g,state.font14,x,y);
            }
            else if(state.IsElliptical){
                g.setColor(Color.green.darker());
                MaestroG.subscripter("ELLIPTICAL POLARIZATION","","",g,state.font14,x,y);
            }
            else if(state.IsCircular){
                g.setColor(Color.magenta.darker());
                MaestroG.subscripter("CIRCULAR POLARIZATION","","",g,state.font14,x,y);
            }
            y+=dy;
            
            if(state.IsLeft){
                g.setColor(Color.blue.darker());
                MaestroG.subscripter("LEFT HANDED","","",g,state.font14,x,y);
            }
            else if(state.IsRight){
                g.setColor(Color.red.darker());
                MaestroG.subscripter("RIGHT HANDED","","",g,state.font14,x,y);
            }
	} 
    }

    class PlaneWaveOutputCanvasB extends Canvas{
	private Font normalfont;
	private Font subfont;
	PlaneWave_State state;
	
        private Image im;
	private Graphics buf;

        public PlaneWaveOutputCanvasB(PlaneWave_State state){
	    super();
	    this.state = state;
	}
	
        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){
            normalfont = new Font("SanSerif",Font.PLAIN,state.font11);
            subfont    = new Font("SanSerif",Font.PLAIN,state.font10);
	
	    int x, y, dx, dxx, dy, dyy, xinit2, xshift1, xshift2, xshift3, fonto;
	    double v_normalized, SA, SB, PA, PB, Pdiff;
	    String unita;
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            g.clearRect(0,0,getSize().width,getSize().height);
            int startx = state.s15;
            
            g.setColor(Color.gray);
            MaestroG.subscripterBold("Output","","",g,state.font14,startx+state.s1,startx+state.s6);
            g.setColor(Color.red.darker());
            MaestroG.subscripterBold("Output","","",g,state.font14,startx,startx+state.s5);
            
            FontMetrics fm;
	    x = state.s10;
	    y = state.s60;
	    dx = state.s80;
	    dxx = state.s15;
            
            xshift1 = state.s40;
            xshift2 = state.s30;
            xshift3 = state.s5;
            
            fonto = state.font11;
            
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight() + state.s2;
	    dyy = dy + state.s10;
            
            xinit2 = x+dxx + state.s90;
            
	    SA = state.Ex*state.Ex/(2.0*Complex.Magnitude(state.wave_impedance))
		    *Math.cos(Complex.Arg1(state.wave_impedance))*Math.exp(-2.0*state.alpha*state.zpos[0]*state.wavelength);
	    SB = state.Ex*state.Ex/(2.0*Complex.Magnitude(state.wave_impedance))
		    *Math.cos(Complex.Arg1(state.wave_impedance))*Math.exp(-2.0*state.alpha*state.zpos[1]*state.wavelength);
	    PA = SA* state.window_area;
	    PB = SB* state.window_area;
	    
	    if(state.zpos[0] < state.zpos[1]){Pdiff = PA - PB;}
	    else{Pdiff = PB - PA;}
	    g.setColor(Color.red.darker());
            //------------------------------------------------------------------ Item 1
	    g.drawString("Time-Average Poynting vector at section A",x,y);	
	    y += dy;
	    g.setColor(Color.black);
	    
            unita="[ W / m\u00b2 ]";
            MaestroG.subscripter("< P(A) >","","",g,state.font12,x+dxx+xshift1,y);
            printdata(SA,g,fonto,xinit2,y,unita);
	    y += dy;
	    //------------------------------------------------------------------ Item 2
            g.setColor(Color.red.darker());
	    g.drawString("Time-Average Power flowing through window A",x,y);
	    y+= dy;
	    g.setColor(Color.black);
	    
            unita="[ W ]";
            MaestroG.subscripterSansBackItalic("< p","t","(A) > = <P(A)> \u00b7","S",g,state.font12,x-state.s10,y);
            printdata(PA,g,fonto,xinit2,y,unita);
	    y += state.s10;
            g.drawLine(5,y,getSize().width-5,y); 
	    y += dy;
	    //------------------------------------------------------------------ Item 3
            g.setColor(Color.red.darker());
	    g.drawString("Time-Average Poynting Vector at section B", x, y);
	    y+= dy;
	    g.setColor(Color.black);
	    unita="[ W / m\u00b2 ]";
            MaestroG.subscripter("< P(B) >","","",g,state.font12,x+dxx+xshift1,y);
            printdata(SB,g,fonto,xinit2,y,unita);
	    y += dy;
            //------------------------------------------------------------------ Item 4
	    g.setColor(Color.red.darker());
	    g.drawString("Time-Average Power flowing through window B",x,y);
	    y+= dy;
	    g.setColor(Color.black);
	    unita="[ W ]";
            MaestroG.subscripterSansBackItalic("< p","t","(B) > = <P(B)> \u00b7","S",g,state.font12,x-state.s10,y);
            printdata(PB,g,fonto,xinit2,y,unita);
	    y += state.s10;
            g.drawLine(5,y,getSize().width-5,y);
	    y += dy;
	    //------------------------------------------------------------------ Item 5
	    g.setColor(Color.red.darker());
            g.drawString("Time-Average Power dissipated between A & B",x,y);
	    y += dy;
	    g.setColor(Color.black);
    	    if(state.zpos[0] < state.zpos[1]){
                MaestroG.subsub("< p","t","(A) - p","t","(B) >",g,state.font12,x+xshift3*4,y);
            }
	    else{
                MaestroG.subsub("< p","t","(B) - p","t","(A) >",g,state.font12,x+xshift3*4,y);
	    }
	    
            unita="[ W ]";
            printdata(Pdiff,g,fonto,xinit2,y,unita);
	}
        
        public static void printdata(double power, Graphics g, int fonto, int xinit2, int y, String unita){
            if(power < 1.0e-15 && power != 0.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e16,5)+"  x  10","-16"," "+unita,g,fonto,xinit2,y);
	    }
            if(power == 0.0){
		MaestroG.superscripter("  =  0.0",""," "+unita,g,fonto,xinit2,y);
	    }
            if(power >= 1.0e-15 && power < 1.0e-14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e15,5)+"  x  10","-15"," "+unita,g,fonto,xinit2,y);
	    }
            if(power >= 1.0e-14 && power < 1.0e-13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e14,5)+"  x  10","-14"," "+unita,g,fonto,xinit2,y);
	    }
            if(power >= 1.0e-13 && power < 1.0e-12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e13,5)+"  x  10","-13"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-12 && power < 1.0e-11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e12,5)+"  x  10","-12"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-11 && power < 1.0e-10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e11,5)+"  x  10","-11"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-10 && power < 1.0e-9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e10,5)+"  x  10","-10"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-9 && power < 1.0e-8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e9,5)+"  x  10","-9"," "+unita,g,fonto,xinit2,y);
	    }
	    
	    if(power >= 1.0e-8 && power < 1.0e-7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e8,5)+"  x  10","-8"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-7 && power < 1.0e-6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e7,5)+"  x  10","-7"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-6 && power < 1.0e-5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e6,5)+"  x  10","-6"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-5 && power < 1.0e-4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e5,5)+"  x  10","-5"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-4 && power < 1.0e-3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e4,5)+"  x  10","-4"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-3 && power < 1.0e-2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e3,5)+"  x  10","-3"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-2 && power < 1.0e-1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e2,5)+"  x  10","-2"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e-1 && power < 1.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e1,5)+"  x  10","-1"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0 && power < 1.0e1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power,5)+"  ",""," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e1 && power < 1.0e2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power,5)+"  ",""," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e2 && power < 1.0e3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-2,5)+"  x  10","2"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e3 && power < 1.0e4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-3,5)+"  x  10","3"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e4 && power < 1.0e5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-4,5)+"  x  10","4"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e5 && power < 1.0e6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-5,5)+"  x  10","5"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e6 && power < 1.0e7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-6,5)+"  x  10","6"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e7 && power < 1.0e8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-7,5)+"  x  10","7"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e8 && power < 1.0e9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-8,5)+"  x  10","8"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e9 && power < 1.0e10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-9,5)+"  x  10","9"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e10 && power < 1.0e11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-10,5)+"  x  10","10"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e11 && power < 1.0e12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-11,5)+"  x  10","11"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e12 && power < 1.0e13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-12,5)+"  x  10","12"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e13 && power < 1.0e14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-13,5)+"  x  10","13"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e14 && power < 1.0e15){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-14,5)+"  x  10","14"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e15 && power < 1.0e16){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-15,5)+"  x  10","15"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e16 && power < 1.0e17){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-16,5)+"  x  10","16"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e17 && power < 1.0e18){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-17,5)+"  x  10","17"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e18 && power < 1.0e19){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-18,5)+"  x  10","18"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e19 && power < 1.0e20){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-19,5)+"  x  10","19"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e20 && power < 1.0e21){
		MaestroG.superscripter("  =  "+MaestroA.rounder(power*1.0e-20,5)+"  x  10","20"," "+unita,g,fonto,xinit2,y);
	    }
	    if(power >= 1.0e21){
		MaestroG.superscripter("  =  "+power+"",""," "+unita,g,fonto,xinit2,y);
	    }
        }
}
