import java.awt.*;

public class ObliqueOutputPanelB extends Panel {
	Oblique_State state;
	private static final Color bgcolor = new Color(200,250,250);//Color.lightGray.brighter();
	private Font labfont;
	private Font titlefont;
	Label titlelabel;
	private Complex temp;	
        public Choice c1;
	
        public ObliqueOutputCanvasD pwocD;
        public ObliqueOutputCanvasE pwocE;
        public ObliqueOutputCanvasF pwocF;
        
        public ObliqueOutputPanelB(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.setForeground(Color.blue.darker());
	    //titlelabel = new Label("",Label.CENTER);
	    //add(titlelabel);
	    //titlelabel.setBounds(15,15,220,35);  
            //titlelabel.setBounds(1,1,150,25);  
	    //titlelabel.setFont(titlefont);
            
            pwocD = new ObliqueOutputCanvasD(state);
	    add(pwocD);
            
            pwocE = new ObliqueOutputCanvasE(state);
	    add(pwocE);
            
            pwocF = new ObliqueOutputCanvasF(state);
	    add(pwocF);
            
            pwocD.setBounds(1,1,state.s300+state.s74,state.s79);
            pwocE.setBounds(1,1,state.s300+state.s74,state.s79);
            pwocF.setBounds(1,1,state.s300+state.s74,state.s79);
            
            pwocD.setVisible(true);
            pwocE.setVisible(true);
            pwocF.setVisible(true);
            
            //pwocD.setBackground(Color.yellow);
	}
	public void paint(Graphics g){
	    //g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);  
	}
   	
}//ObliqueOutputPanel.java

class ObliqueOutputCanvasD 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 static int prec1 = 6;
        public static int prec2 = 6;

	public ObliqueOutputCanvasD(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;
	    x = state.s5;
            x3 = state.s10;
            x4 = state.s35;
            x2 = state.s200+state.s30;
	    y = state.s18;
	    dx = state.s80;
	    dxx = state.s15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    
            int fonto = state.font12;
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    
	    g.setFont(normalfont2);
	    fm = g.getFontMetrics();
	    dy = state.s20;
	    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;
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    if(state.isPolarizationParallel){
                
                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){
                    g.setColor(Color.blue);
                    MaestroG.supsubsubUn("H","i","//","y"," = - H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("H","r","//","y"," = "+MaestroA.rounder(R1_neg,6)+" H","0"," y","^","  [ A /m ]",g,fonto,x3,y);           
                    }
                    else{
                        MaestroG.supsubsubUn("H","r","//","y"," = ( "+R3_neg+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);                        
                    }
                   
                    y+= dyy;
                        
                   if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("H","t","//","y"," = "+MaestroA.rounder(T1_neg,6)+" H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    else{
                        MaestroG.supsubsubUn("H","t","//","y"," = ( "+T3_neg+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    }
                }
                else{// flip incident direction
                    g.setColor(Color.blue);
                    MaestroG.supsubsubUn("H","i","//","y"," = H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("H","r","//","y"," = "+(MaestroA.rounder(R1,6))+" H","0"," y","^","  [ A /m ]",g,fonto,x3,y);                        
                    }
                    else{
                        MaestroG.supsubsubUn("H","r","//","y"," = ( "+R3+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("H","t","//","y"," = "+T1+" H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    else{
                        MaestroG.supsubsubUn("H","t","//","y"," = ( "+T3+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    }
                }
            }
            else{
                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),6);
                R2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),6);
                R3 = new Complex(R1,R2);
                R1_neg = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_Coef),6);
                R2_neg = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_Coef),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_CoefH),6);
                RE2 = MaestroA.rounder(Complex.Imaginary(state.Reflection_CoefH),6);
                RE3 = new Complex(RE1,RE2);
                RE1_neg = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_CoefH),6);
                RE2_neg = MaestroA.rounder(-1.0*Complex.Imaginary(state.Reflection_CoefH),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){
                    g.setColor(Color.magenta.darker());
                    MaestroG.supsubsubUn("E","i","","\u22a5y"," = - E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("E","r","","\u22a5y"," = "+R1_neg+" E","0"," y","^","  [ V/m ]",g,fonto,x3,y);           
                    }
                    else{
                        MaestroG.supsubsubUn("E","r","","\u22a5y"," = ( "+R3_neg+" ) E","0"," y","^","  [ V/m ]",g,fonto,x3,y);                        
                    }
                    
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("E","t","","\u22a5y"," = "+T1_neg+" E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    else{
                        MaestroG.supsubsubUn("E","t","","\u22a5y"," = ( "+T3_neg+" ) E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    }
                }
                else{// flip incident direction
                    g.setColor(Color.magenta.darker());
                    MaestroG.supsubsubUn("E","i","","\u22a5y"," = E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("E","r","","\u22a5y"," = "+R1+" E","0"," y","^","  [ V/m ]",g,fonto,x3,y);                        
                    }
                    else{
                        MaestroG.supsubsubUn("E","r","","\u22a5y"," = ( "+R3+" ) E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("E","t","","\u22a5y"," = "+T1+" E","0"," y","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    else{
                        MaestroG.supsubsubUn("E","t","","\u22a5y"," = ( "+T3+" ) E","0"," y","^","  [ V/m ]",g,fonto,x3,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("  =  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 ObliqueOutputCanvasE 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 static int prec1 = 6;
        public static int prec2 = 6;

	public ObliqueOutputCanvasE(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;
	    x = state.s5;
            x3 = state.s10;
            x4 = state.s35;
            x2 = state.s200+state.s30;
	    y = state.s18;
	    dx = state.s80;
	    dxx = state.s15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    int fonto = state.font12;
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    
	    g.setFont(normalfont2);
	    fm = g.getFontMetrics();
	    dy = state.s20;
	    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;
	    
	    if(state.isPolarizationParallel){
                
                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 = 0.0;
                T2 = 0.0;
                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 = 0.0;
                TE2 = 0.0;
                TE3 = new Complex(TE1,TE2);
                
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
                if(state.IsVectorIn){
                    
                    g.setColor(Color.magenta.darker());
                    
                    //MaestroG.subsubsubUn("","E","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" H","0"," \u00e2","x","  [ V/m ]",g,fonto,x3,y);
                    MaestroG.supsubsubUn("E","i","//","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                   if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        //MaestroG.subsubsubUn("","E","xR"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                          //                                    Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" H","0"," \u00e2","x","  [ V/m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("E","r","//","x"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" H","0"," x","^","  [ 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(),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","xR"," = ( "+tmpz+" ) H","0"," \u00e2","x","  [ V/m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("E","r","//","x"," = ( "+tmpz+" ) H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                        
                    
                        MaestroG.supsubsubUn("E","t","//","x"," = "+T1+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    
                }
                else{// flip incident direction
                    
                    g.setColor(Color.magenta.darker());
                    //MaestroG.subsubsubUn("","E","x"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" H","0"," \u00e2","x","  [ V/m ]",g,fonto,x3,y);
                    MaestroG.supsubsubUn("E","i","//","x"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        //MaestroG.subsubsubUn("","E","xR"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*
                          //                                    Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" H","0"," \u00e2","x","  [ V/m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("E","r","//","x"," = "+MaestroA.rounder((-1.0)*Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" H","0"," x","^","  [ 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(),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","xR"," = ( "+tmpz+" ) H","0"," \u00e2","x","  [ V/m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("E","r","//","x"," = ( "+tmpz+" ) H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                        MaestroG.supsubsubUn("E","t","//","x"," = "+T1+" H","0"," x","^","  [ V/m ]",g,fonto,x3,y);
                }
            }
            else{
                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 = 0.0;
                T2 = 0.0;
                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 = 0.0;
                TE2 = 0.0;
                TE3 = new Complex(TE1,TE2);
                
                if(state.IsVectorIn){
                    g.setColor(Color.blue);
                    //MaestroG.subsubsubUn("","H","x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" E","0"," \u00e2","x","  [ A /m ]",g,fonto,x3,y);
                    MaestroG.supsubsubUn("H","i","","\u22a5x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        //MaestroG.subsubsubUn("","H","xR"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*
                            //                                  Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" E","0"," \u00e2","x","  [ A /m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("H","r","","\u22a5x"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" E","0"," x","^","  [ 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(),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","xR"," = ( "+tmpz+" ) E","0"," \u00e2","x","  [ A /m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("H","r","","\u22a5x"," = ( "+tmpz+" ) E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                    
                    MaestroG.supsubsubUn("H","t","","\u22a5x"," = "+T1+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                }
                else{// flip incident direction
                    g.setColor(Color.blue);
                    MaestroG.supsubsubUn("H","i","","\u22a5x"," = "+MaestroA.rounder((-1.0)/Complex.Real(state.wave_impedance1)*Math.cos(state.theta1),6)+" E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubUn("H","r","","\u22a5x"," = "+MaestroA.rounder(1.0/Complex.Real(state.wave_impedance1)*
                                                              Math.cos(state.theta1)*MaestroA.rounder(R1,6),6)+" E","0"," x","^","  [ 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(),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","xR"," = ( "+tmpz+" ) E","0"," \u00e2","x","  [ A /m ]",g,fonto,x3,y);
                        MaestroG.supsubsubUn("H","r","","\u22a5x"," = ( "+tmpz+" ) E","0"," x","^","  [ A /m ]",g,fonto,x3,y);
                    }
                    
                    y+= dyy;
                    
                        MaestroG.supsubsubUn("H","t","","\u22a5x"," = "+T1+" E","0"," x","^","  [ A /m ]",g,fonto,x3,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 ObliqueOutputCanvasF 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 static int prec1 = 6;
        public static int prec2 = 6;

	public ObliqueOutputCanvasF(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;
	    x = state.s5;
            x3 = state.s10;
            x4 = state.s35;
            x2 = state.s200+state.s30;
	    y = state.s18;
	    dx = state.s80;
	    dxx = state.s15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    int fonto = state.font12;
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    
	    g.setFont(normalfont2);
	    fm = g.getFontMetrics();
	    dy = state.s20;
	    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;
	    
	    if(state.isPolarizationParallel){
                
                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 = 0.0;
                T2 = 0.0;
                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 = 0.0;
                TE2 = 0.0;
                TE3 = new Complex(TE1,TE2);
                
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
                if(state.IsVectorIn){
                    g.setColor(Color.magenta.darker());
                    MaestroG.supsubsubsubsub2("","\u03b5","1","E","i","//","z"," = "+MaestroA.rounder(state.epsilon_r1*Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03b5","0","H","0"," z","^"," [ C/m\u00b2 ]", g,fonto,x3,y);
                    y+= dyy;
                   
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubsubsub2("","\u03b5","1","E","r","//","z"," = "+MaestroA.rounder(Complex.Real(state.wave_impedance1)*
                                                              Math.sin(state.theta1)*state.epsilon_r1*
                                                              MaestroA.rounder(R1,6),prec2)+" \u03b5","0","H","0"," z","^"," [ 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(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.supsubsubsubsub2("","\u03b5","1","E","r","//","z"," = ( "+tmpx+" ) \u03b5","0","H","0"," z","^"," [ C/m\u00b2 ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy;
                        MaestroG.supsubsubsubsub2("","\u03b5","2","E","t","//","z"," = "+T1+" \u03b5","0","H","0"," z","^"," [ C/m\u00b2 ]",g,fonto,x3,y);
                }
                else{// flip incident direction
                    g.setColor(Color.magenta.darker());
                    MaestroG.supsubsubsubsub2("","\u03b5","1","E","i","//","z"," = "+MaestroA.rounder((-1.0)*state.epsilon_r1*Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03b5","0","H","0"," z","^"," [ C/m\u00b2 ]",g,fonto,x3,y);
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubsubsub2("","\u03b5","1","E","r","//","z"," = "+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"," z","^"," [ 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(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.supsubsubsubsub2("","\u03b5","1","E","r","//","z"," = ( "+tmpx+" ) \u03b5","0","H","0"," z","^"," [ C/m\u00b2 ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy;
                    
                    MaestroG.supsubsubsubsub2("","\u03b5","2","E","t","//","z"," = "+T1+" \u03b5","0","H","0"," z","^"," [ C/m\u00b2 ]",g,fonto,x3,y);
                }
            }
            else{
                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 = 0.0;
                T2 = 0.0;
                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 = 0.0;
                TE2 = 0.0;
                TE3 = new Complex(TE1,TE2);
                
                if(state.IsVectorIn){
                    
                    g.setColor(Color.blue);
                    MaestroG.supsubsubsubsub2("","\u03bc","1","H","i","","\u22a5z"," = "+MaestroA.rounder((-1.0)*state.mu_r1/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03bc","0","E","0"," z","^","  [ T ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        
                        MaestroG.supsubsubsubsub2("","\u03bc","1","H","r","","\u22a5z"," = "+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"," z","^","  [ 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(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.supsubsubsubsub2("","\u03bc","1","H","r","","\u22a5z"," = ( "+tmpx+" ) \u03bc","0","E","0"," z","^","  [ T ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy;
                    
                    MaestroG.supsubsubsubsub2("","\u03bc","2","H","t","","\u22a5z"," = "+T1+" \u03bc","0","E","0"," z","^","  [ T ]",g,fonto,x3,y);
                }
                else{// flip incident direction
                    g.setColor(Color.blue);
                    MaestroG.supsubsubsubsub2("","\u03bc","1","H","i","","\u22a5z"," = "+MaestroA.rounder((1.0)*state.mu_r1/Complex.Real(state.wave_impedance1)*Math.sin(state.theta1),prec2)+" \u03bc","0","E","0"," z","^","  [ T ]",g,fonto,x3,y);
                    
                    y+= dyy;
                        
                    if(state.theta1 < (state.totalR_angle*Math.PI/180.0)){
                        MaestroG.supsubsubsubsub2("","\u03bc","1","H","r","","\u22a5z"," = "+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"," z","^","  [ 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(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.supsubsubsubsub2("","\u03bc","1","H","r","","\u22a5z"," = ( "+tmpx+" ) \u03bc","0","E","0"," z","^","  [ T ]",g,fonto,x3,y); 
                    }
                    
                    y+= dyy;
                    
                    MaestroG.supsubsubsubsub2("","\u03bc","2","H","t","","\u22a5z"," = "+T1+" \u03bc","0","E","0"," z","^","  [ T ]",g,fonto,x3,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);
        }
}
