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

public class ObliqueOutputPanel extends Panel implements ItemListener{
	Oblique_State state;
	private static final Color bgcolor = Color.lightGray.brighter();
	private Font labfont;
	private Font titlefont;
	Label titlelabel;
	private Complex temp;	
        public Choice c1;
	public ObliqueOutputCanvasA pwocA; 
        public ObliqueOutputCanvasB pwocB;
        public ObliqueOutputCanvasB2 pwocB2;
        public ObliqueOutputCanvasC pwocC;
        public ObliqueOutputCanvasC2 pwocC2;
        
        public ObliqueOutputPanel(Oblique_State state){
	    super();
            setLayout(null);
	    setBackground(bgcolor);
	    this.state = state;
            
            labfont = new Font("Sanserif",Font.PLAIN,state.font12);
            titlefont = new Font("Sanserif",Font.BOLD,state.font16);
            
	    titlelabel = new Label("",Label.CENTER);
	    //add(titlelabel);
	    titlelabel.setBounds(state.s1,state.s1,state.s150,state.s25);
	    titlelabel.setFont(titlefont);
            
            c1 = new Choice();
	    c1.addItem(" Reflection Behavior");
	    c1.addItem(" Propagation Data");
            c1.addItem(" Field Phasors at (0,0,0)");
            add(c1);
            // CHANGE ==========================================================
	    c1.setBounds(state.s85,state.s5,state.s200,state.s22);
            c1.setFont(new java.awt.Font("SanSerif",Font.ITALIC,state.font11));
	    //==================================================================
	    c1.setBackground(bgcolor.brighter());
	    
	    pwocA = new ObliqueOutputCanvasA(state);
	    add(pwocA);
            pwocB = new ObliqueOutputCanvasB(state);
	    add(pwocB);
            pwocB2 = new ObliqueOutputCanvasB2(state);
	    add(pwocB2);
            pwocC = new ObliqueOutputCanvasC(state);
	    add(pwocC);
            pwocC2 = new ObliqueOutputCanvasC2(state);
	    add(pwocC2);
            
            pwocA.setBounds(state.s1,state.s1,state.s200+state.s98-1,state.s200+state.s80);
            pwocB.setBounds(state.s1,state.s1,state.s200+state.s98-1,state.s200+state.s80);
            pwocB2.setBounds(state.s1,state.s1,state.s200+state.s98-1,state.s200+state.s80);
            pwocC.setBounds(state.s1,state.s1,state.s200+state.s98-1,state.s200+state.s80);
            pwocC2.setBounds(state.s1,state.s1,state.s200+state.s98-1,state.s200+state.s80);
            
            pwocA.setVisible(true);
            pwocB.setVisible(false);
            pwocB2.setVisible(false);
            pwocC.setVisible(false);
            pwocC2.setVisible(false);
            
            //Listeners
	    c1.addItemListener(this);
	}
        
	public void paint(Graphics g){
	    //g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);  
	}
        
        public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]==" Reflection Behavior"){
		    pwocA.setVisible(true);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(false);
                    pwocC.setVisible(false);
                    pwocC2.setVisible(false);
		}
		//else if(ie.getSelectedObjects()[0]==" Propagation Data 1"){
                else if(ie.getSelectedObjects()[0]==" Propagation Data"){
		    pwocA.setVisible(false);
		    pwocB.setVisible(true);
                    pwocB2.setVisible(false);
		    pwocC.setVisible(false);
                    pwocC2.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]==" Propagation Data 2"){// not used here
		    pwocA.setVisible(false);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(true);
		    pwocC.setVisible(false);
                    pwocC2.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]==" Field Phasors at (0,0,0)"){
		    pwocA.setVisible(false);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(false);
		    pwocC.setVisible(true);
                    pwocC2.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]==" Boundary Conditions"){// not used here
		    pwocA.setVisible(false);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(false);
		    pwocC.setVisible(false);
                    pwocC2.setVisible(true);
		}
	    }
    }	
	
}//ObliqueOutputPanel.java

class ObliqueOutputCanvasA extends Canvas{
	
	private Font normalfont;
        private Font normalfont2;
	private Font subfont;
	private Font titlefont;
	private Font symbfont;
	Oblique_State state;
	private Image im;
	private Graphics buf;

	public ObliqueOutputCanvasA(Oblique_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){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	    int x, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2;
	    double temp3, temp4, temp5, ratioZ, test1, test2, test3, factor1;
	    
            normalfont = new Font("Sanserif",Font.PLAIN,state.font12);
            normalfont2 = new Font("Sanserif",Font.PLAIN,state.font11);
            subfont    = new Font("Sanserif",Font.PLAIN,state.font10);
            titlefont  =new Font("Sanserif",Font.BOLD,state.font16);
            symbfont = new Font("Serif",Font.PLAIN,state.font13);
	
            FontMetrics fm;
	    x = state.s10;
	    y = state.s40;
	    dx = state.s80;
	    dxx = state.s15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",state.s20,state.s20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = state.s15;
	    dyy = dy;
	    y+=dyy;
	    g.setColor(Color.red.darker());
	    g.drawString("Incident Angle",x+dxx - state.s5,y);	
	    g.drawString("Refraction Angle",x + 2*dx - state.s10,y);
	    y += dy;
	    g.setColor(Color.black);
	    MaestroG.subscripter("\u03b8","i"," = "+MaestroA.rounder(state.theta1*180.0/Math.PI,4)+"\u00ba",g,state.font12,x+dxx,y);
	    g.setFont(normalfont);
	    
	    MaestroG.subscripter("\u03b8","t"," = N/A",g,state.font12,x+2*dx-state.s5,y);
            g.setFont(normalfont);
            y += dyy;
            g.drawLine(state.s5,y,getSize().width-state.s5,y); 
	    y += dyy;
	    
	    g.setColor(Color.red.darker());
	    g.drawString("Electric Field",x,y);
            
	    y+= dy;
	    
            g.setColor(Color.blue.darker());
	    g.drawString("Reflection Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    temp3 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),4);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    g.drawString(" = "+temp2+"",x+dx+dx+state.s7,y);
	    g.setFont(symbfont);
	    g.drawString("\u0393",x+2*dx-state.s5,y);
	    g.setFont(normalfont);
            
	    y+= dy;
    	    
            g.setColor(Color.blue.darker());
	    g.drawString("Transmission Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    
	    temp3 = MaestroA.rounder(Complex.Real(state.Transmission_Coef),4);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.Transmission_Coef),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    g.setFont(symbfont);
            MaestroG.SerifSymbFirst(" \u03c4","","",g,state.font12,x+dx+dx-state.s5,y);
	    g.setFont(normalfont);
            g.drawString(" = "+temp2+"",x+dx+dx+state.s7,y);
            
            y += dyy;
	    g.drawLine(state.s5,y,getSize().width-state.s5,y); 
	    y += dyy;
	    
            g.setColor(Color.red.darker());
	    g.drawString("Magnetic Field",x,y);
	    
	    y+= dy;
            g.setColor(Color.blue.darker());
	    g.drawString("Reflection Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    
	    temp3 = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_Coef),4);
	    temp4 = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_Coef),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    g.drawString(" = "+temp2+"",x+dx+dx+state.s7,y);
	    g.setFont(symbfont);
	    g.drawString("\u0393",x+2*dx-state.s5,y);
	    g.setFont(normalfont);

	    y+= dy;
            
            g.setColor(Color.blue.darker());
	    g.drawString("Transmission Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    ratioZ = Complex.Real(Complex.Divide(state.wave_impedance1,state.wave_impedance2));
	    temp3 = MaestroA.rounder(ratioZ*Complex.Real(state.Transmission_Coef),4);
	    temp4 = MaestroA.rounder(ratioZ*Complex.Imaginary(state.Transmission_Coef),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    g.setFont(symbfont);
            MaestroG.SerifSymbFirst(" \u03c4","","",g,state.font12,x+dx+dx-state.s5,y);
	    g.setFont(normalfont);
	    g.drawString(" = "+temp2+"",x+dx+dx+state.s7,y);
            
            y += dyy;
	    g.drawLine(state.s5,y,getSize().width-state.s5,y);
	    y += dyy;
	    
	    g.setColor(Color.red.darker());
	    g.drawString("Power",x,y);
	    
	    y+= dy;
            
	    g.setColor(Color.blue.darker());
	    g.drawString("Reflectivity",x+dxx,y);
	    g.setColor(Color.black);
	    temp3 = Complex.Magnitude(state.Reflection_Coef);
	    temp4 = temp3*temp3;
	    g.drawString(" = "+MaestroA.rounder(temp4,6)+"",x+dx+dx+state.s7,y);
	    g.setFont(symbfont);
	    g.drawString("R",x+2*dx-state.s5,y);
	    g.setFont(normalfont);

	    y+= dy;
            
    	    g.setColor(Color.blue.darker());
	    g.drawString("Transmissivity",x+dxx,y);
	    g.setColor(Color.black);
	    temp5 = 1.0 - temp4;
	    
	    g.drawString(" = "+MaestroA.rounder(temp5,6)+"",x+dx+dx+state.s7,y);
	    g.setFont(symbfont);
	    g.drawString("T",x+2*dx-state.s5,y);
	    g.setFont(normalfont);
	}
}

class ObliqueOutputCanvasB extends Canvas{
	
	private Font normalfont;
        private Font normalfont2;
	private Font subfont;
	private Font titlefont;
	private Font symbfont;
	Oblique_State state;
	private Image im;
	private Graphics buf;

	public ObliqueOutputCanvasB(Oblique_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.font12);
            normalfont2 = new Font("Sanserif",Font.PLAIN,state.font11);
            subfont = new Font("Sanserif",Font.PLAIN,state.font10);
            titlefont = new Font("Sanserif",Font.BOLD,state.font16);
            symbfont = new Font("Serif",Font.PLAIN,state.font13);
            
            int x, x2, x3, x4, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2;
	    double temp3, temp4, temp5, ratioZ, test1, test2, test3, factor1;
	    FontMetrics fm;
	    
            dx = state.s80;
	    dxx = state.s15;
            x = state.s50;
            x2 = state.s34;
            x3 = x+dxx+state.s150;
            x4 = state.s20;
	    y = state.s30;
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    
            g.clearRect(0,0,getSize().width,getSize().height);
	    
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",state.s20,state.s20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = state.s15;
	    dyy = dy;
            int xplus = state.s150;
	    
            g.setColor(Color.red.darker());
	    y+= dy;
            //--------------------------------------------- MEDIUM 1
            int fonto = state.font12;
            int fonto2 = state.font11;
            double test;
            
            g.setColor(Color.red.darker());
            g.drawString("Wavelength",x4,y);
	    g.drawString("Medium 1",x3,y);
	    g.setColor(Color.black);
            
	    y += dy;
	    test = state.wavelength1;
            MaestroG.subscripterSS2("\u03bb","1","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+state.s2;
            g.setColor(Color.red.darker());
            g.drawString("Impedance",x4,y);
	    g.setColor(Color.black);
	    y += dy;
	    test = state.wave_impedance1.Real();
            MaestroG.subscripterSS2("\u03b7","1","",g,fonto,x2,y);
	    MaestroG.subscripterSS2(" [ \u03a9",""," ]",g,fonto,x+dxx+xplus,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+state.s2;
            g.setColor(Color.red.darker());
            g.drawString("Incident wave vector",x4,y);
	    g.setColor(Color.black);
	    y += dy;// Total beta
	    test = state.beta1;
            MaestroG.subscripter3("k","i","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x+dxx+xplus,y);
	    Write(g,test,fonto,x,y);
            
            y += dy+state.s1;// x-component
            test = state.beta1_z;
            MaestroG.subscripter3("k","i","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x+dxx+xplus,y);
	    Write(g,test,fonto,x,y);
            
	    y += dy+1;// z-component
            if(state.theta1 < Math.PI*0.5){
                test = state.beta1_x;
            }
            else{
                test = 0.0;
            }
            MaestroG.subscripter3("k","i","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x+dxx+xplus,y);
	    Write(g,test,fonto,x,y);
            
            y += dy+state.s5;
            
            g.setColor(Color.red.darker());
            g.drawString("Apparent wavelengths",x4,y);
	    //g.drawString("Medium 1",x3,y);
	    g.setColor(Color.black);
            
	    y += dy;
	    test = state.wavelength1z;
            
            MaestroG.subscripter3("\u03bb","1","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    
            if(state.theta1 == 0.0){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
            y += dy;
	    test = state.wavelength1x;
            MaestroG.subscripter3("\u03bb","1","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    
            if(state.theta1 == Math.PI*0.5){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
            y += dyy+state.s5;
            g.setColor(Color.red.darker());
            g.drawString("Apparent phase velocities",x4,y);
	    g.setColor(Color.black);
            y += dy+1;// z-component
            test = state.phase_velocity1z;
            
            MaestroG.subscripter3("u","1","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
	    if(state.theta1 == 0.0){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
	    y += dy+1;// x-component
            
            test = state.phase_velocity1x;
            MaestroG.subscripter3("u","1","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
	    if(state.theta1 < Math.PI*0.5){
                Write(g,test,fonto,x,y);
            }
            else{
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
	}

        public void Write(Graphics g, double test, int fonto, int x, int y){
            Graphics2D g2d = (Graphics2D)g;
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            //if(test < 1.0e-15){
		//MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e16,5)+"  x  10","-16"," ",g,fonto,x,y);
	    //}
            if(test < 1.0e-15){
		MaestroG.superscripter("  =  0.0",""," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-15 && test < 1.0e-14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e15,5)+"  x  10","-15"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-14 && test < 1.0e-13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e14,5)+"  x  10","-14"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-13 && test < 1.0e-12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e13,5)+"  x  10","-13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-12 && test < 1.0e-11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e12,5)+"  x  10","-12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-11 && test < 1.0e-10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e11,5)+"  x  10","-11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-10 && test < 1.0e-9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e10,5)+"  x  10","-10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-9 && test < 1.0e-8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e9,5)+"  x  10","-9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-8 && test < 1.0e-7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e8,5)+"  x  10","-8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-7 && test < 1.0e-6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e7,5)+"  x  10","-7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-6 && test < 1.0e-5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e6,5)+"  x  10","-6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-5 && test < 1.0e-4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e5,5)+"  x  10","-5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-4 && test < 1.0e-3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e4,5)+"  x  10","-4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-3 && test < 1.0e-2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e3,5)+"  x  10","-3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-2 && test < 1.0e-1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e2,5)+"  x  10","-2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-1 && test < 1.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e1,5)+"  x  10","-1"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0 && test < 1.0e1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e1 && test < 1.0e2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e2 && test < 1.0e3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-2,5)+"  x  10","2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e3 && test < 1.0e4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-3,5)+"  x  10","3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e4 && test < 1.0e5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-4,5)+"  x  10","4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e5 && test < 1.0e6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-5,5)+"  x  10","5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e6 && test < 1.0e7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-6,5)+"  x  10","6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e7 && test < 1.0e8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-7,5)+"  x  10","7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e8 && test < 1.0e9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-8,5)+"  x  10","8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e9 && test < 1.0e10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-9,5)+"  x  10","9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e10 && test < 1.0e11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-10,5)+"  x  10","10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e11 && test < 1.0e12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-11,5)+"  x  10","11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e12 && test < 1.0e13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-12,5)+"  x  10","12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e13 && test < 1.0e14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-13,5)+"  x  10","13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e14 && test < 1.0e15){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-14,5)+"  x  10","14"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e15 && test < 1.0e16){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-15,5)+"  x  10","15"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e16 && test < 1.0e17){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-16,5)+"  x  10","16"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e17 && test < 1.0e18){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-17,5)+"  x  10","17"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e18 && test < 1.0e19){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-18,5)+"  x  10","18"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e19 && test < 1.0e20){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-19,5)+"  x  10","19"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e20 && test < 1.0e21){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-20,5)+"  x  10","20"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e21){
		MaestroG.superscripter("  =  "+test+"",""," ",g,fonto,x,y);
	    }
            
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }

        public void WriteC(Graphics g, double test, int fonto, int x, int y){
            Graphics2D g2d = (Graphics2D)g;
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
            
            //if(test < 1.0e-15){
		//MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e16,5)+"  x  10","-16"," ",g,fonto,x,y);
	    //}
            if(test < 1.0e-15){
		MaestroG.superscripter("  =  0.0",""," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-15 && test < 1.0e-14){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e15,5)+"  x  10","-15"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-14 && test < 1.0e-13){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e14,5)+"  x  10","-14"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-13 && test < 1.0e-12){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e13,5)+"  x  10","-13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-12 && test < 1.0e-11){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e12,5)+"  x  10","-12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-11 && test < 1.0e-10){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e11,5)+"  x  10","-11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-10 && test < 1.0e-9){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e10,5)+"  x  10","-10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-9 && test < 1.0e-8){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e9,5)+"  x  10","-9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-8 && test < 1.0e-7){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e8,5)+"  x  10","-8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-7 && test < 1.0e-6){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e7,5)+"  x  10","-7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-6 && test < 1.0e-5){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e6,5)+"  x  10","-6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-5 && test < 1.0e-4){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e5,5)+"  x  10","-5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-4 && test < 1.0e-3){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e4,5)+"  x  10","-4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-3 && test < 1.0e-2){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e3,5)+"  x  10","-3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-2 && test < 1.0e-1){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e2,5)+"  x  10","-2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-1 && test < 1.0){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e1,5)+"  x  10","-1"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0 && test < 1.0e1){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e1 && test < 1.0e2){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e2 && test < 1.0e3){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-2,5)+"  x  10","2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e3 && test < 1.0e4){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-3,5)+"  x  10","3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e4 && test < 1.0e5){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-4,5)+"  x  10","4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e5 && test < 1.0e6){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-5,5)+"  x  10","5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e6 && test < 1.0e7){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-6,5)+"  x  10","6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e7 && test < 1.0e8){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-7,5)+"  x  10","7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e8 && test < 1.0e9){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-8,5)+"  x  10","8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e9 && test < 1.0e10){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-9,5)+"  x  10","9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e10 && test < 1.0e11){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-10,5)+"  x  10","10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e11 && test < 1.0e12){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-11,5)+"  x  10","11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e12 && test < 1.0e13){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-12,5)+"  x  10","12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e13 && test < 1.0e14){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-13,5)+"  x  10","13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e14 && test < 1.0e15){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-14,5)+"  x  10","14"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e15 && test < 1.0e16){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-15,5)+"  x  10","15"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e16 && test < 1.0e17){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-16,5)+"  x  10","16"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e17 && test < 1.0e18){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-17,5)+"  x  10","17"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e18 && test < 1.0e19){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-18,5)+"  x  10","18"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e19 && test < 1.0e20){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-19,5)+"  x  10","19"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e20 && test < 1.0e21){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-20,5)+"  x  10","20"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e21){
		MaestroG.superscripter("  =  - j "+test+"",""," ",g,fonto,x,y);
	    }
            
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
}

class ObliqueOutputCanvasB2 extends Canvas{
	
	private Font normalfont;
        private Font normalfont2;
	private Font subfont;
	private Font titlefont;
	private Font symbfont;
	Oblique_State state;
	private Image im;
	private Graphics buf;

	public ObliqueOutputCanvasB2(Oblique_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);
            normalfont2 = new Font("Sanserif",Font.PLAIN,state.font12);
            subfont = new Font("Sanserif",Font.PLAIN,state.font10);
            titlefont = new Font("Sanserif",Font.BOLD,state.font16);
            symbfont = new Font("Serif",Font.PLAIN,state.font13);
            int x, x2, x3, x4, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2;
	    double temp3, temp4, temp5, ratioZ, test1, test2, test3, factor1;
	    FontMetrics fm;
	    
            dx = state.s80;
	    dxx = state.s15;
            x = state.s50;
            int xplus = state.s150;
            x2 = state.s34;
            x3 = x+dxx+xplus;
            x4 = state.s20;
	    y = state.s30;
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    
            g.clearRect(0,0,getSize().width,getSize().height);
	    
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",state.s20,state.s20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = state.s14;
	    dyy = dy;
	    
            g.setColor(Color.red.darker());
	    
	    y+= dy;
	    
            //--------------------------------------------- MEDIUM 1
            int fonto = state.font11;
            int fonto2 = state.font12;
            double test;
            
            g.setColor(Color.red.darker());
            g.drawString("Apparent wavelengths",x4,y);
	    g.drawString("Medium 1",x3,y);
	    g.setColor(Color.black);
            
	    y += dy;
	    test = state.wavelength1z;
            
            MaestroG.subscripter3("\u03bb","1","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    
            if(state.theta1 == 0.0){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
            y += dy;
	    test = state.wavelength1x;
            MaestroG.subscripter3("\u03bb","1","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    
            if(state.theta1 == Math.PI*0.5){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
            y += dyy+state.s2;
            g.setColor(Color.red.darker());
            g.drawString("Phase velocity",x4,y);
	    g.setColor(Color.black);
	    y += dy;
	    test = state.phase_velocity1;
            MaestroG.subscripter3("u","1","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+1;
            g.setColor(Color.red.darker());
            g.drawString("Apparent phase velocities",x4,y);
	    g.setColor(Color.black);
            y += dy+1;// z-component
            test = state.phase_velocity1z;
            MaestroG.subscripter3("u","1","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
	    if(state.theta1 == 0.0){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
	    y += dy+1;// x-component
            
            test = state.phase_velocity1x;
            MaestroG.subscripter3("u","1","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
	    if(state.theta1 < Math.PI*0.5){
                Write(g,test,fonto,x,y);
            }
            else{
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            
            y += state.s8;
            
            g.setColor(Color.green.darker());
            g.drawLine(state.s10,y,getSize().width-state.s10,y);
            
            //------------------------------------ MEDIUM 
            y += dyy;
            g.setColor(Color.blue.darker());
            g.drawString("Apparent wavelengths",x4,y);
	    g.drawString("Medium 2",x3,y);
            g.setColor(Color.black);
            
	    y += dy;
	    test = state.wavelength2z;
            MaestroG.subscripter3("\u03bb","2","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    
            if(state.theta1 == 0.0){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else if(state.theta1 >= (state.totalR_angle*Math.PI/180.0)){
                test = state.wavelength1z;
                Write(g,test,fonto,x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
            y += dy;
	    test = state.wavelength2x;
            MaestroG.subscripter3("\u03bb","2","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+xplus,y);
	    if(state.theta1 >= (state.totalR_angle*Math.PI/180.0)){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
            y += dyy+state.s2;
            g.setColor(Color.blue.darker());
            g.drawString("Phase velocity",x4,y);
	    g.setColor(Color.black);
            double testangle;
            
            testangle = Math.PI/180.0*state.totalR_angle;
            
	    y += dy;
            if(state.theta1 < testangle){
                test = state.phase_velocity2;
                MaestroG.subscripter3("u","2","","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
                Write(g,test,fonto,x,y);
            }
            else{
                MaestroG.subscripter3("u","2","","","= undefined (evanescent wave)",g,fonto,x2,y);
                MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
            }
            
            y += dyy+state.s1;
            g.setColor(Color.blue.darker());
            g.drawString("Apparent phase velocities",x4,y);
	    g.setColor(Color.black);
            y += dy+state.s1;// z-component
            
            test = state.phase_velocity1z;
            MaestroG.subscripter3("u","2","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
	    
            if(state.theta1 == 0.0){
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            else{
                Write(g,test,fonto,x,y);
            }
            
	    y += dy+state.s1;// x-component
            
            
            if(state.theta1 < testangle){
                test = state.phase_velocity2x;
                MaestroG.subscripter3("u","2","z","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
                Write(g,test,fonto,x,y);
            }
            else{
                MaestroG.subscripter3("u","2","z","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+xplus,y);
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            
            
	    g.setFont(normalfont);
	    
            //-----------------------------------------------------------------------
            
	}

        public void Write(Graphics g, double test, int fonto, int x, int y){
            Graphics2D g2d = (Graphics2D)g;
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
            //if(test < 1.0e-15){
		//MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e16,5)+"  x  10","-16"," ",g,fonto,x,y);
	    //}
            if(test < 1.0e-15){
		MaestroG.superscripter("  =  0.0",""," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-15 && test < 1.0e-14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e15,5)+"  x  10","-15"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-14 && test < 1.0e-13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e14,5)+"  x  10","-14"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-13 && test < 1.0e-12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e13,5)+"  x  10","-13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-12 && test < 1.0e-11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e12,5)+"  x  10","-12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-11 && test < 1.0e-10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e11,5)+"  x  10","-11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-10 && test < 1.0e-9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e10,5)+"  x  10","-10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-9 && test < 1.0e-8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e9,5)+"  x  10","-9"," ",g,fonto,x,y);
	    }
	    
	    else if(test >= 1.0e-8 && test < 1.0e-7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e8,5)+"  x  10","-8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-7 && test < 1.0e-6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e7,5)+"  x  10","-7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-6 && test < 1.0e-5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e6,5)+"  x  10","-6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-5 && test < 1.0e-4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e5,5)+"  x  10","-5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-4 && test < 1.0e-3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e4,5)+"  x  10","-4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-3 && test < 1.0e-2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e3,5)+"  x  10","-3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-2 && test < 1.0e-1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e2,5)+"  x  10","-2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-1 && test < 1.0){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e1,5)+"  x  10","-1"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0 && test < 1.0e1){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e1 && test < 1.0e2){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e2 && test < 1.0e3){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-2,5)+"  x  10","2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e3 && test < 1.0e4){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-3,5)+"  x  10","3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e4 && test < 1.0e5){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-4,5)+"  x  10","4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e5 && test < 1.0e6){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-5,5)+"  x  10","5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e6 && test < 1.0e7){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-6,5)+"  x  10","6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e7 && test < 1.0e8){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-7,5)+"  x  10","7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e8 && test < 1.0e9){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-8,5)+"  x  10","8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e9 && test < 1.0e10){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-9,5)+"  x  10","9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e10 && test < 1.0e11){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-10,5)+"  x  10","10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e11 && test < 1.0e12){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-11,5)+"  x  10","11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e12 && test < 1.0e13){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-12,5)+"  x  10","12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e13 && test < 1.0e14){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-13,5)+"  x  10","13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e14 && test < 1.0e15){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-14,5)+"  x  10","14"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e15 && test < 1.0e16){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-15,5)+"  x  10","15"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e16 && test < 1.0e17){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-16,5)+"  x  10","16"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e17 && test < 1.0e18){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-17,5)+"  x  10","17"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e18 && test < 1.0e19){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-18,5)+"  x  10","18"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e19 && test < 1.0e20){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-19,5)+"  x  10","19"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e20 && test < 1.0e21){
		MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e-20,5)+"  x  10","20"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e21){
		MaestroG.superscripter("  =  "+test+"",""," ",g,fonto,x,y);
	    }
            
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }

        public void WriteC(Graphics g, double test, int fonto, int x, int y){
            Graphics2D g2d = (Graphics2D)g;
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
            
            //if(test < 1.0e-15){
		//MaestroG.superscripter("  =  "+MaestroA.rounder(test*1.0e16,5)+"  x  10","-16"," ",g,fonto,x,y);
	    //}
            if(test < 1.0e-15){
		MaestroG.superscripter("  =  0.0",""," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-15 && test < 1.0e-14){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e15,5)+"  x  10","-15"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-14 && test < 1.0e-13){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e14,5)+"  x  10","-14"," ",g,fonto,x,y);
	    }
            else if(test >= 1.0e-13 && test < 1.0e-12){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e13,5)+"  x  10","-13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-12 && test < 1.0e-11){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e12,5)+"  x  10","-12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-11 && test < 1.0e-10){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e11,5)+"  x  10","-11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-10 && test < 1.0e-9){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e10,5)+"  x  10","-10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-9 && test < 1.0e-8){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e9,5)+"  x  10","-9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-8 && test < 1.0e-7){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e8,5)+"  x  10","-8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-7 && test < 1.0e-6){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e7,5)+"  x  10","-7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-6 && test < 1.0e-5){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e6,5)+"  x  10","-6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-5 && test < 1.0e-4){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e5,5)+"  x  10","-5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-4 && test < 1.0e-3){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e4,5)+"  x  10","-4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-3 && test < 1.0e-2){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e3,5)+"  x  10","-3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-2 && test < 1.0e-1){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e2,5)+"  x  10","-2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e-1 && test < 1.0){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e1,5)+"  x  10","-1"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0 && test < 1.0e1){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e1 && test < 1.0e2){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test,5)+"  ",""," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e2 && test < 1.0e3){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-2,5)+"  x  10","2"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e3 && test < 1.0e4){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-3,5)+"  x  10","3"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e4 && test < 1.0e5){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-4,5)+"  x  10","4"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e5 && test < 1.0e6){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-5,5)+"  x  10","5"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e6 && test < 1.0e7){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-6,5)+"  x  10","6"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e7 && test < 1.0e8){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-7,5)+"  x  10","7"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e8 && test < 1.0e9){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-8,5)+"  x  10","8"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e9 && test < 1.0e10){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-9,5)+"  x  10","9"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e10 && test < 1.0e11){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-10,5)+"  x  10","10"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e11 && test < 1.0e12){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-11,5)+"  x  10","11"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e12 && test < 1.0e13){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-12,5)+"  x  10","12"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e13 && test < 1.0e14){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-13,5)+"  x  10","13"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e14 && test < 1.0e15){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-14,5)+"  x  10","14"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e15 && test < 1.0e16){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-15,5)+"  x  10","15"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e16 && test < 1.0e17){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-16,5)+"  x  10","16"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e17 && test < 1.0e18){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-17,5)+"  x  10","17"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e18 && test < 1.0e19){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-18,5)+"  x  10","18"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e19 && test < 1.0e20){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-19,5)+"  x  10","19"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e20 && test < 1.0e21){
		MaestroG.superscripter("  =  - j "+MaestroA.rounder(test*1.0e-20,5)+"  x  10","20"," ",g,fonto,x,y);
	    }
	    else if(test >= 1.0e21){
		MaestroG.superscripter("  =  - j "+test+"",""," ",g,fonto,x,y);
	    }
            
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
}

class ObliqueOutputCanvasC extends Canvas{
	
	private Font normalfont;
        private Font normalfont2;
	private Font subfont;
	private Font titlefont;
	private Font symbfont;
	Oblique_State state;
	private Image im;
	private Graphics buf;

	public ObliqueOutputCanvasC(Oblique_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.font12);
            normalfont2 = new Font("Sanserif",Font.PLAIN,state.font12);
            subfont = new Font("Sanserif",Font.PLAIN,state.font10);
            titlefont = new Font("Sanserif",Font.BOLD,state.font16);
            symbfont = new Font("Serif",Font.PLAIN,state.font13);
            int x, x2, x3, x4, y, dx, dxx, dy, dyy, prec1;
	    Complex temp1, temp2;
	    double temp3, temp4, temp5, ratioZ, test1, test2, test3, factor1;
	    FontMetrics fm;
            prec1 = 6;
	    x = state.s5;
            x3 = state.s10;
            x4 = state.s35;
            x2 = state.s200+state.s30;
	    y = state.s20;
	    dx = state.s80;
	    dxx = state.s15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    int fonto = state.font12;
	    int fonto2 = state.font12;
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	    
            g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",state.s20,state.s20);

	    g.setFont(normalfont2);
	    fm = g.getFontMetrics();
	    dy = state.s13;
	    dyy = dy+state.s4;
	    
            double radiusH = state.s6;
            double xpos = x + state.s10;
            double ypos2 = y+dy;
            double xpos2 = x + state.s10;
            double ypos = y+dy;
            
            y+=dy + state.s5;
	    
	    if(state.isPolarizationParallel){
                g.setColor(Color.blue);
                g.drawString("Parallel Polarization ( TM )",x4,y);
                y+= dyy;
                g.setFont(normalfont);
                fm = g.getFontMetrics();
                
                double R1, R2, R1_neg, R2_neg;
                Complex R3, R3_neg;
                R1 = MaestroA.rounder(Complex.Real(state.Reflection_CoefH),6);
                R2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_CoefH),6);
                R3 = new Complex(R1,R2);
                R1_neg = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_CoefH),6);
                R2_neg = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_CoefH),6);
                R3_neg = new Complex(R1_neg,R2_neg);
                
                double T1, T2, T1_neg, T2_neg;
                Complex T3, T3_neg;
                T1 = 0.0;
                T2 = 0.0;
                T3 = new Complex(T1,T2);
                T1_neg = 0.0;
                T2_neg = 0.0;
                T3_neg = new Complex(T1_neg,T2_neg);
                
                double RE1, RE2, RE1_neg, RE2_neg;
                Complex RE3, RE3_neg;
                RE1 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),6);
                RE2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),6);
                RE3 = new Complex(RE1,RE2);
                RE1_neg = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_Coef),6);
                RE2_neg = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_Coef),6);
                RE3_neg = new Complex(RE1_neg,RE2_neg);
                
                double TE1, TE2, TE1_neg, TE2_neg;
                Complex TE3, TE3_neg;
                TE1 = 0.0;
                TE2 = 0.0;
                TE3 = new Complex(TE1,TE2);
                TE1_neg = 0.0;
                TE2_neg = 0.0;
                TE3_neg = new Complex(TE1_neg,TE2_neg);
                
                if(state.IsVectorIn){
                    
                    MaestroG.fillCircleThick(g, xpos2, ypos2, radiusH, 2, Color.white);
                    MaestroG.drawLineThick(g, xpos2-(double)(radiusH/2), ypos2-(double)(radiusH/2),
                                    xpos2 + (double)(radiusH/2), ypos2 + (double)(radiusH/2), 2, Color.blue);
                    MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), 2,Color.blue);           
                    MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, 2, Color.blue);
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    g.setColor(Color.black);
                    
                    MaestroG.subscripterB("Incident Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn3("","H","y"," = - H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                    MaestroG.subsubsubUn3("","E","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*Math.cos(state.theta1), prec1)+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    MaestroG.subsubsubUn3("","E","z"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.sin(state.theta1), prec1)+" H","0"," z","^","  [ V/m ]",g,fonto,x3,y);
                    
                    y+= dyy+state.s5;
                    
                   g.setColor(Color.black);
                   MaestroG.subscripterB("Reflected Wave","","",g,fonto2,x3,y);
                   y+= dyy;
                   
                   g.setColor(Color.blue);
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn3("","H","y"," = "+MaestroA.rounder(R1_neg, prec1)+" H","0"," y","^","  [ A /m ]",g,fonto,x3,y);           
                    }
                    else{
                        MaestroG.subsubsubUn3("","H","y"," = ( "+R3_neg+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);                        
                    }
                    
                    y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                   if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn3("","E","x"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6), prec1)+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","E","z"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*MaestroA.rounder(R1,6), prec1)+" H","0"," z","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    else{
                        
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Multiply(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        
                        MaestroG.subsubsubUn3("","E","x"," = ( "+tmpz+" ) H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        MaestroG.subsubsubUn3("","E","z"," = ( "+tmpx+" ) H","0"," z","^","  [ V/m ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy+state.s5;
                    
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Transmitted Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.blue);    
                    MaestroG.subsubsubUn3("","H","y"," = "+T1_neg,""," y","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                   
                        MaestroG.subsubsubUn3("","E","x"," = "+T1,""," x","^","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","E","z"," = "+T1,""," z","^","  [ V/m ]",g,fonto,x3,y);
                    
                }
                else{// flip incident direction
                    
                    MaestroG.fillCircleThick(g, xpos, ypos, radiusH, 2, Color.white);
                    MaestroG.drawCircleThick(g, xpos, ypos, 1.0,2, Color.blue);
                    MaestroG.drawCircleThick(g, xpos, ypos, radiusH, 2, Color.blue);
                    
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    g.setColor(Color.black);
                    
                    MaestroG.subscripterB("Incident Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn3("","H","y"," = H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    MaestroG.subsubsubUn3("","E","x"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),prec1)+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    MaestroG.subsubsubUn3("","E","z"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec1)+" H","0"," z","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy+state.s5;
                    
                   g.setColor(Color.black);
                   MaestroG.subscripterB("Reflected Wave","","",g,fonto2,x3,y);
                   y+= dyy;
                   
                   g.setColor(Color.blue);
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn3("","H","y"," = "+(MaestroA.rounder(R1,prec1))+" H","0"," y","^","  [ A /m ]",g,fonto,x3,y);                        
                    }
                    else{
                        MaestroG.subsubsubUn3("","H","y"," = ( "+R3+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        
                        MaestroG.subsubsubUn3("","E","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),prec1)+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","E","z"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*MaestroA.rounder(R1,6),prec1)+" H","0"," z","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    else{
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Multiply(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        
                        MaestroG.subsubsubUn3("","E","x"," = ( "+tmpz+" ) H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        
                        MaestroG.subsubsubUn3("","E","z"," = ( "+tmpx+" ) H","0"," z","^","  [ V/m ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy+state.s5;
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Transmitted Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    
                        MaestroG.subsubsubUn3("","H","y"," = "+T1,""," y","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                        MaestroG.subsubsubUn3("","E","x"," = "+T1,""," x","^","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","E","z"," = "+T1,""," z","^","  [ V/m ]",g,fonto,x3,y);
                }
            }
            else{
                g.setColor(Color.magenta.darker());
                g.drawString("Perpendicular Polarization ( TE )", x4, y);
                y+= dyy;
                g.setFont(normalfont);
                fm = g.getFontMetrics();
                
                double R1, R2, R1_neg, R2_neg;
                Complex R3, R3_neg;
                R1 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),prec1);
                R2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),prec1);
                R3 = new Complex(R1,R2);
                R1_neg = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_Coef),prec1);
                R2_neg = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_Coef),prec1);
                R3_neg = new Complex(R1_neg,R2_neg);
                
                double T1, T2, T1_neg, T2_neg;
                Complex T3, T3_neg;
                T1 = 0.0;
                T2 = 0.0;
                T3 = new Complex(T1,T2);
                T1_neg = 0.0;
                T2_neg = 0.0;
                T3_neg = new Complex(T1_neg,T2_neg);
                
                double RE1, RE2, RE1_neg, RE2_neg;
                Complex RE3, RE3_neg;
                RE1 = MaestroA.rounder(Complex.Real(state.Reflection_CoefH),prec1);
                RE2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_CoefH),prec1);
                RE3 = new Complex(RE1,RE2);
                RE1_neg = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_CoefH),prec1);
                RE2_neg = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_CoefH),prec1);
                RE3_neg = new Complex(RE1_neg,RE2_neg);
                
                double TE1, TE2, TE1_neg, TE2_neg;
                Complex TE3, TE3_neg;
                TE1 = 0.0;
                TE2 = 0.0;
                TE3 = new Complex(TE1,TE2);
                TE1_neg = 0.0;
                TE2_neg = 0.0;
                TE3_neg = new Complex(TE1_neg,TE2_neg);
                
                if(state.IsVectorIn){
                    MaestroG.fillCircleThick(g, xpos2, ypos2, radiusH, 2, Color.white);
                    MaestroG.drawLineThick(g, xpos2-(double)(radiusH/2), ypos2-(double)(radiusH/2),
                                    xpos2 + (double)(radiusH/2), ypos2 + (double)(radiusH/2), 1, Color.magenta.darker());
                    MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), 1,Color.magenta.darker());           
                    MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, 2, Color.magenta.darker());
                    
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Incident Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.magenta.darker());
                    MaestroG.subsubsubUn3("","E","y"," = - E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn3("","H","x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),prec1)+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    MaestroG.subsubsubUn3("","H","z"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec1)+" E","0"," z","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy+state.s5;
                    
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Reflected Wave","","",g,fonto2,x3,y);
                    
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                        
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn3("","E","y"," = "+R1_neg+" E","0"," y","^","  [ V/m ]",g,fonto,x3,y);           
                    }
                    else{
                        MaestroG.subsubsubUn3("","E","y"," = ( "+R3_neg+" ) E","0"," y","^","  [ V/m ]",g,fonto,x3,y);                        
                    }
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                          //                                    Math.cos(state.theta1)*MaestroA.rounder(R1,6),prec1)+" E","0"," \u00e2","x","  [ A /m ]",g,fonto,x3,y);
                        MaestroG.subsubsubUn3("","H","x"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),prec1)+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","H","z"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*MaestroA.rounder(R1,6),prec1)+" E","0"," z","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    else{
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Divide(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        
                        MaestroG.subsubsubUn3("","H","x"," = ( "+tmpz+" ) E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        MaestroG.subsubsubUn3("","H","z"," = ( "+tmpx+" ) E","0"," z","^","  [ A /m ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy+state.s5;
                    
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Transmitted Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                        MaestroG.subsubsubUn3("","E","y"," = "+T1_neg,""," y","^","  [ V/m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    
                        MaestroG.subsubsubUn3("","H","x"," = "+T1,""," x","^","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","H","z"," = "+T1,""," z","^","  [ A /m ]",g,fonto,x3,y);
                }
                else{// flip incident direction
                    
                    MaestroG.fillCircleThick(g, xpos, ypos, radiusH, 2, Color.white);
                    MaestroG.drawCircleThick(g, xpos, ypos, 1.0,2, Color.magenta.darker());
                    MaestroG.drawCircleThick(g, xpos, ypos, radiusH, 2, Color.magenta.darker());
                    g.setColor(Color.magenta.darker());
                    
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    g.setColor(Color.black);
                     
                     MaestroG.subscripterB("Incident Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.magenta.darker());
                    MaestroG.subsubsubUn3("","E","y"," = E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn3("","H","x"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),prec1)+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    MaestroG.subsubsubUn3("","H","z"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec1)+" E","0"," z","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy+state.s5;
                    
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Reflected Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                        
                    g.setColor(Color.magenta.darker());
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn3("","E","y"," = "+(MaestroA.rounder(R1,prec1))+" E","0"," y","^","  [ V/m ]",g,fonto,x3,y);                        
                    }
                    else{
                        MaestroG.subsubsubUn3("","E","y"," = ( "+R3+" ) E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn3("","H","x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),prec1)+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubUn3("","H","z"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*MaestroA.rounder(R1,6),prec1)+" E","0"," z","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    else{
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Divide(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec1));
                        }
                        MaestroG.subsubsubUn3("","H","x"," = ( "+tmpz+" ) E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),prec1))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),prec1))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec1));
                        }
                        
                        MaestroG.subsubsubUn3("","H","z"," = ( "+tmpx+" ) E","0"," z","^","  [ A /m ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy+state.s5;
                    
                    g.setColor(Color.black);
                    MaestroG.subscripterB("Transmitted Wave","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                    MaestroG.subsubsubUn3("","E","y"," = "+T1,""," y","^","  [ V/m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                    MaestroG.subsubsubUn3("","H","x"," = "+T1,""," x","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                        
                    MaestroG.subsubsubUn3("","H","z"," = "+T1,""," z","^","  [ A /m ]",g,fonto,x3,y);    
                }
            }
	}
}

class ObliqueOutputCanvasC2 extends Canvas{// Fields with Boundary Conditions - not changed to new reference - UNUSED
	
	private static final Font normalfont = new Font("Sanserif",Font.PLAIN,11);
        private static final Font normalfont2 = new Font("Sanserif",Font.PLAIN,12);
	private static final Font subfont    = new Font("Sanserif",Font.PLAIN,10);
	private static final Font titlefont  =new Font("Sanserif",Font.BOLD,16);
	private static final Font symbfont = new Font("Serif",Font.PLAIN,13);
	Oblique_State state;
	private Image im;
	private Graphics buf;
        
        public static int prec1 = 6;
        public static int prec2 = 4;

	public ObliqueOutputCanvasC2(Oblique_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){
            int x, x2, x3, x4, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2;
	    double temp3, temp4, temp5, ratioZ, test1, test2, test3, factor1;
	    FontMetrics fm;
	    x = 5;
            x3 = 10;
            x4 = 35;
            x2 = 230;
	    y = 25;
	    dx = 80;
	    dxx = 15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    int fonto = 11;
            int fonto2 = 12;
            
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",20,20);

	    g.setFont(normalfont2);
	    fm = g.getFontMetrics();
	    dy = 14;//fm.getHeight()-1;
	    dyy = dy+4;
	    
            double radiusH = 6;
            double xpos = x+10;
            double ypos2 = y+dy;
            double xpos2 = x+10;
            double ypos = y+dy;
            
            y+=dy+5;
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	    
	    if(state.isPolarizationParallel){
                g.setColor(Color.blue);
                g.drawString("Parallel Polarization ( TM )",x4,y);
                y+= dyy;
                g.setFont(normalfont);
                fm = g.getFontMetrics();
                
                double R1, R2;
                Complex R3;
                R1 = MaestroA.rounder(Complex.Real(state.Reflection_CoefH),6);
                R2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_CoefH),6);
                R3 = new Complex(R1,R2);
                    
                double T1, T2;
                Complex T3;
                T1 = MaestroA.rounder(Complex.Real(state.Transmission_CoefH),6);
                T2 = MaestroA.rounder(Complex.Imaginary(state.Transmission_CoefH),6);
                T3 = new Complex(T1,T2);
                
                double RE1, RE2;
                Complex RE3;
                RE1 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),6);
                RE2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),6);
                RE3 = new Complex(RE1,RE2);
                    
                double TE1, TE2;
                Complex TE3;
                TE1 = MaestroA.rounder(Complex.Real(state.Transmission_Coef),6);
                TE2 = MaestroA.rounder(Complex.Imaginary(state.Transmission_Coef),6);
                TE3 = new Complex(TE1,TE2);
                
                if(state.IsVectorIn){
                    
                    MaestroG.fillCircleThick(g, xpos2, ypos2, radiusH, 2, Color.white);
                    MaestroG.drawLineThick(g, xpos2-(double)(radiusH/2), ypos2-(double)(radiusH/2),
                                    xpos2 + (double)(radiusH/2), ypos2 + (double)(radiusH/2), 2, Color.blue);
                    MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), 2,Color.blue);
                    MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, 2, Color.blue);
                
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn("","H","y"," = H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                    MaestroG.subsubsubUn("","E","z"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    MaestroG.subsubsubsubsub("","\u03b5","1","E","x"," = "+MaestroA.rounder(state.epsilon_r1*Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]", g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                   g.setColor(Color.black);
                   MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto2,x3,y);
                   y+= dyy;
                   
                   g.setColor(Color.blue);
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","H","y"," = "+MaestroA.rounder(R1,6)+" H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);           
                    }
                    else{
                        MaestroG.subsubsubUn("","H","y"," = ( "+R3+" ) H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);                        
                    }
                    
                    y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                   if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","E","z"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubsubsub("","\u03b5","1","E","x"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*state.epsilon_r1*
                                                              MaestroA.rounder(R1,6),prec2)+" \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                    }
                    else{
                        
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        
                        Ctempz = Complex.Multiply(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubUn("","E","z"," = ( "+tmpz+" ) H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*state.epsilon_r1*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r1*Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*state.epsilon_r1*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r1*Ctempx.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubsubsub("","\u03b5","1","E","x"," = ( "+tmpx+" ) \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y); 
                        
                    }
                    
                    y+= dyy+5;
                    
                   g.setColor(Color.black);
                   MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                        
                   g.setColor(Color.blue);
                   if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","H","y"," = "+MaestroA.rounder(T1,6)+" H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    }
                    else{
                        
                        MaestroG.subsubsubUn("","H","y"," = ( "+T3+" ) H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    }
                    y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","E","z"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance2)*
                                                              Math.cos(state.theta2)*MaestroA.rounder(T1,6),6)+" H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubsubsub("","\u03b5","2","E","x"," = "+MaestroA.rounder(state.epsilon_r2*Complex.Real(state.wave_impedance2)*
                                                              Math.sin(state.theta2)*MaestroA.rounder(T1,6),prec2)+" \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                    }
                    else{
                        
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz, CtempTot;
                        Ctempz = Complex.Add(MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6),
                                                  Complex.Multiply(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1)
                                                 );
                        
                        Ctempz = Complex.Multiply(-1.0,Ctempz);
                        
                        Ctempx = Complex.Multiply(Complex.Subtract(MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),6),
                                                  Complex.Multiply(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1)
                                                 ), state.epsilon_r1/state.epsilon_r2);
                        
                        CtempTot = Complex.Add(Ctempx,Ctempz);
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        MaestroG.subsubsubUn("","E","z"," = ( "+tmpz+" ) H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(state.epsilon_r2*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r2*Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(state.epsilon_r2*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r2*Ctempx.Imaginary()),prec2));
                        }
                        MaestroG.subsubsubsubsub("","\u03b5","2","E","x"," = ( "+tmpx+" ) \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                        
                        //System.out.println(CtempTot);
                    }
                    
                }
                else{// flip incident direction
                    
                    MaestroG.fillCircleThick(g, xpos, ypos, radiusH, 2, Color.white);
                    MaestroG.drawCircleThick(g, xpos, ypos, 1.0,2, Color.blue);
                    MaestroG.drawCircleThick(g, xpos, ypos, radiusH, 2, Color.blue);
                    
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn("","H","y"," = - H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    MaestroG.subsubsubUn("","E","z"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    //MaestroG.subsubsub("","E","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),6)+" H","0"," \u00e2","x",g,fonto,x3,y);
                    MaestroG.subsubsubsubsub("","\u03b5","1","E","x"," = "+MaestroA.rounder((-1.0)*state.epsilon_r1*Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                    y+= dyy+5;
                    
                   g.setColor(Color.black);
                   MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto2,x3,y);
                   y+= dyy;
                   
                   g.setColor(Color.blue);
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","H","y"," = "+(-1.0 * MaestroA.rounder(R1,6))+" H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);                        
                    }
                    else{
                        MaestroG.subsubsubUn("","H","y"," = ( "+Complex.Multiply(R3,new Complex(-1.0,0.0))+" ) H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","E","z"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        
                        MaestroG.subsubsubsubsub("","\u03b5","1","E","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*state.epsilon_r1*
                                                              MaestroA.rounder(R1,6),prec2)+" \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                    }
                    else{
                        
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Multiply(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubUn("","E","z"," = ( "+tmpz+" ) H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(state.epsilon_r1*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r1*Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(state.epsilon_r1*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r1*Ctempx.Imaginary()),prec2));
                        }
                        
                        //MaestroG.subsubsub("","E","x"," = ( "+tmpx+" ) H","0"," \u00e2","x",g,fonto,x3,y); 
                        MaestroG.subsubsubsubsub("","\u03b5","1","E","x"," = ( "+tmpx+" ) \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy+5;
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","H","y"," = "+(-1.0 * MaestroA.rounder(T1,6))+" H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    }
                    else{
                        
                        MaestroG.subsubsubUn("","H","y"," = ( "+Complex.Multiply(T3,new Complex(-1.0,0.0))+" ) H","0"," \u00e2","y","  [ A /m ]",g,fonto,x3,y);
                    }
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","E","z"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance2)*
                                                              Math.cos(state.theta2)*MaestroA.rounder(T1,6),6)+" H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        //MaestroG.subsubsub("","E","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance2)*
                          //                                    Math.sin(state.theta2)*MaestroA.rounder(T1,6),6)+" H","0"," \u00e2","x",g,fonto,x3,y);
                        MaestroG.subsubsubsubsub("","\u03b5","2","E","x"," = "+MaestroA.rounder((-1.0)*state.epsilon_r2*Complex.Real(state.wave_impedance2)*
                                                              Math.sin(state.theta2)*MaestroA.rounder(T1,6),prec2)+" \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                    }
                    else{
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz, CtempTot;
                        Ctempz = Complex.Add(MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6),
                                                  Complex.Multiply(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1)
                                                 );
                        
                        Ctempx = Complex.Multiply(Complex.Subtract(MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),6),
                                                  Complex.Multiply(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1)
                                                 ), state.epsilon_r1/state.epsilon_r2);
                        
                        Ctempx = Complex.Multiply(-1.0,Ctempx);
                        
                        CtempTot = Complex.Add(Ctempx,Ctempz);
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        MaestroG.subsubsubUn("","E","z"," = ( "+tmpz+" ) H","0"," \u00e2","z","  [ V/m ]",g,fonto,x3,y);
                        y+= dyy;
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(state.epsilon_r2*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r2*Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(state.epsilon_r2*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(state.epsilon_r2*Ctempx.Imaginary()),prec2));
                        }
                        //MaestroG.subsubsub("","E","x"," = ( "+tmpx+" ) H","0"," \u00e2","x",g,fonto,x3,y);
                        MaestroG.subsubsubsubsub("","\u03b5","2","E","x"," = ( "+tmpx+" ) \u03b5","0","H","0"," \u00e2","x"," [ C/m\u00b2 ]",g,fonto,x3,y);
                        //System.out.println(CtempTot);
                        
                    }
                    
                }
            }
            else{
                g.setColor(Color.magenta.darker());
                g.drawString("Perpendicular Polarization ( TE )",x4,y);
                y+= dyy;
                g.setFont(normalfont);
                fm = g.getFontMetrics();
                
                double R1, R2;
                Complex R3;
                R1 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),6);
                R2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),6);
                R3 = new Complex(R1,R2);
                    
                double T1, T2;
                Complex T3;
                T1 = MaestroA.rounder(Complex.Real(state.Transmission_Coef),6);
                T2 = MaestroA.rounder(Complex.Imaginary(state.Transmission_Coef),6);
                T3 = new Complex(T1,T2);
                
                double RE1, RE2;
                Complex RE3;
                RE1 = MaestroA.rounder(Complex.Real(state.Reflection_CoefH),6);
                RE2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_CoefH),6);
                RE3 = new Complex(RE1,RE2);
                    
                double TE1, TE2;
                Complex TE3;
                TE1 = MaestroA.rounder(Complex.Real(state.Transmission_CoefH),6);
                TE2 = MaestroA.rounder(Complex.Imaginary(state.Transmission_CoefH),6);
                TE3 = new Complex(TE1,TE2);
                
                if(state.IsVectorIn){
                    
                    MaestroG.fillCircleThick(g, xpos2, ypos2, radiusH, 2, Color.white);
                    MaestroG.drawLineThick(g, xpos2-(double)(radiusH/2), ypos2-(double)(radiusH/2),
                                    xpos2 + (double)(radiusH/2), ypos2 + (double)(radiusH/2), 2, Color.magenta.darker());
                    MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), 2,Color.magenta.darker());
                    MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, 2, Color.magenta.darker());
                
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.magenta.darker());
                    MaestroG.subsubsubUn("","E","y"," = E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn("","H","z"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    MaestroG.subsubsubsubsub("","\u03bc","1","H","x"," = "+MaestroA.rounder((-1.0)*state.mu_r1/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                        
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","E","y"," = "+MaestroA.rounder(R1,6)+" E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);           
                    }
                    else{
                        MaestroG.subsubsubUn("","E","y"," = ( "+R3+" ) E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);                        
                    }
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","H","z"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubsubsub("","\u03bc","1","H","x"," = "+MaestroA.rounder((-1.0)*state.mu_r1/Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*MaestroA.rounder(R1,6),prec2)+" \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                        
                    }
                    else{
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Divide(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubUn("","H","z"," = ( "+tmpz+" ) E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(state.mu_r1*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(state.mu_r1*Math.abs(Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(state.mu_r1*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(state.mu_r1*Math.abs(Ctempx.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubsubsub("","\u03bc","1","H","x"," = ( "+tmpx+" ) \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y); 
                        
                    }
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","E","y"," = "+MaestroA.rounder(T1,6)+" E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    }
                    else{
                        
                        MaestroG.subsubsubUn("","E","y"," = ( "+T3+" ) E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","H","z"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance2)*
                                                              Math.cos(state.theta2)*MaestroA.rounder(T1,6),6)+" E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        MaestroG.subsubsubsubsub("","\u03bc","2","H","x"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance2)*
                                                              Math.sin(state.theta2)*MaestroA.rounder(T1,6),prec2)+" \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                                                              
                        
                    }
                    else{
                        
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz, CtempTot;
                        Ctempz = Complex.Add(MaestroA.rounder(Math.cos(state.theta1)/Complex.Real(state.wave_impedance1),6),
                                                  Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1)
                                                 );
                                 
                        Ctempx = Complex.Multiply(Complex.Subtract(MaestroA.rounder(Math.sin(state.theta1)/Complex.Real(state.wave_impedance1),6),
                                                  Complex.Divide(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1)
                                                 ), state.mu_r1/state.mu_r2);
                        Ctempx = Complex.Multiply(-1.0,Ctempx);
                        
                        CtempTot = Complex.Add(Ctempx,Ctempz);
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        MaestroG.subsubsubUn("","H","z"," = ( "+tmpz+" ) E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(state.mu_r2*Ctempx.Real(),prec2))+" + j "+String.valueOf(state.mu_r2*MaestroA.rounder(Math.abs(Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(state.mu_r2*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(state.mu_r2*Math.abs(Ctempx.Imaginary()),prec2));
                        }
                        MaestroG.subsubsubsubsub("","\u03bc","2","H","x"," = ( "+tmpx+" ) \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                        
                        //System.out.println(CtempTot);
                        
                    }
                    
                }
                else{// flip incident direction
                    
                    MaestroG.fillCircleThick(g, xpos, ypos, radiusH, 2, Color.white);
                    MaestroG.drawCircleThick(g, xpos, ypos, 1.0,2, Color.magenta.darker());
                    MaestroG.drawCircleThick(g, xpos, ypos, radiusH, 2, Color.magenta.darker());
                    g.setColor(Color.magenta.darker());
                    
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    //
                     
                     MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    g.setColor(Color.magenta.darker());
                    MaestroG.subsubsubUn("","E","y"," = - E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    MaestroG.subsubsubUn("","H","z"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    //MaestroG.subsubsub("","H","x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),6)+" E","0"," \u00e2","x",g,fonto,x3,y);
                    MaestroG.subsubsubsubsub("","\u03bc","1","H","x"," = "+MaestroA.rounder((1.0)*state.mu_r1/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                        
                    g.setColor(Color.magenta.darker());
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","E","y"," = "+(-1.0 * MaestroA.rounder(R1,6))+" E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);                        
                    }
                    else{
                        MaestroG.subsubsubUn("","E","y"," = ( "+Complex.Multiply(R3,new Complex(-1.0,0.0))+" ) E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","H","z"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        //MaestroG.subsubsub("","H","x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*
                          //                                    Math.sin(state.theta1)*MaestroA.rounder(R1,6),6)+" E","0"," \u00e2","x",g,fonto,x3,y);
                        MaestroG.subsubsubsubsub("","\u03bc","1","H","x"," = "+MaestroA.rounder((1.0)*state.mu_r1/Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*MaestroA.rounder(R1,6),prec2)+" \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                        
                    }
                    else{
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Divide(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1);
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubUn("","H","z"," = ( "+tmpz+" ) E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        
                        
                        y+= dyy;
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*state.mu_r1*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(state.mu_r1*Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*state.mu_r1*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(state.mu_r1*Ctempx.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubsubsub("","\u03bc","1","H","x"," = ( "+tmpx+" ) \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y); 
                        
                    }
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto2,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.subsubsubUn("","E","y"," = "+(-1.0 * MaestroA.rounder(T1,6))+" E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    }
                    else{
                        
                        MaestroG.subsubsubUn("","E","y"," = ( "+Complex.Multiply(T3,new Complex(-1.0,0.0))+" ) E","0"," \u00e2","y","  [ V/m ]",g,fonto,x3,y);
                    }
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.subsubsubUn("","H","z"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance2)*
                                                              Math.cos(state.theta2)*MaestroA.rounder(T1,6),6)+" E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        
                        MaestroG.subsubsubsubsub("","\u03bc","2","H","x"," = "+MaestroA.rounder((1.0)/Complex.Real(state.wave_impedance2)*
                                                              Math.sin(state.theta2)*MaestroA.rounder(T1,6),prec2)+" \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                        
                    }
                    else{
                        
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz, CtempTot;
                        Ctempz = Complex.Add(MaestroA.rounder(Math.cos(state.theta1)/Complex.Real(state.wave_impedance1),6),
                                                  Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1)
                                                 );
                        
                        Ctempz = Complex.Multiply(-1.0,Ctempz);
                                 
                        Ctempx = Complex.Multiply(Complex.Subtract(MaestroA.rounder(Math.sin(state.theta1)/Complex.Real(state.wave_impedance1),6),
                                                  Complex.Divide(Complex.Multiply(Math.sin(state.theta1),RE3),state.wave_impedance1)
                                                 ), state.mu_r1/state.mu_r2);
                        
                         CtempTot = Complex.Add(Ctempx,Ctempz);
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),prec2));
                        }
                        MaestroG.subsubsubUn("","H","z"," = ( "+tmpz+" ) E","0"," \u00e2","z","  [ A /m ]",g,fonto,x3,y);
                        y+= dyy;
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(state.mu_r2*Ctempx.Real(),prec2))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(state.mu_r2*Ctempx.Imaginary()),prec2));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(state.mu_r2*Ctempx.Real(),prec2))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(state.mu_r2*Ctempx.Imaginary()),prec2));
                        }
                        
                        MaestroG.subsubsubsubsub("","\u03bc","2","H","x"," = ( "+tmpx+" ) \u03bc","0","E","0"," \u00e2","x","  [ T ]",g,fonto,x3,y);
                        
                    }  
                }
            }
	}
}