//ObliqueOutputPanel.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//import java.lang.*;  

public class ObliqueOutputPanel extends Panel implements ItemListener{
	Oblique_State state;
	private static final Color bgcolor = Color.lightGray.brighter();
	private static final Font labfont=new Font("Sanserif",Font.PLAIN,12);
	private static final Font titlefont=new Font("Sanserif",Font.BOLD,16);
	Label titlelabel;
	private Complex temp;	
        public Choice c1;
	ObliqueOutputCanvasA pwocA; 
        ObliqueOutputCanvasB pwocB;
        ObliqueOutputCanvasB2 pwocB2;
        ObliqueOutputCanvasB3 pwocB3;
        ObliqueOutputCanvasC pwocC;
        
        public ObliqueOutputPanel(Oblique_State state){
	    super();
            setLayout(null);
	    setBackground(bgcolor);
	    this.state = state;
            //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);
            
            c1 = new Choice();
	    c1.addItem(" Refraction Behavior 1");
            c1.addItem(" Refraction Behavior 2");
	    c1.addItem(" Propagation Data");
            //c1.addItem(" Propagation Data 2");
            //c1.addItem(" Propagation Data 3");
            c1.addItem(" Field Phasors at (0,0,0)");
	    add(c1);
	    // Change ==========================================================
	    //c1.setBounds(105,6,180,20);
            c1.setBounds(85,5,200,22);
            //==================================================================
	    
	    c1.setBackground(bgcolor.brighter());
	    
	    
	    Panel ps1 = new Panel();
	    ps1.setBackground(Color.cyan);
	    //add(ps1);
	    ps1.setBounds(153,4,104,24);
	    
	    Panel ps2 = new Panel();
	    ps2.setBackground(Color.black);
	    //add(ps2);
	    ps2.setBounds(152,3,106,26);
            
	    pwocA = new ObliqueOutputCanvasA(state);
	    add(pwocA);
            pwocB = new ObliqueOutputCanvasB(state);
	    add(pwocB);
            pwocB2 = new ObliqueOutputCanvasB2(state);
	    add(pwocB2);
            pwocB3 = new ObliqueOutputCanvasB3(state);
	    add(pwocB3);
            pwocC = new ObliqueOutputCanvasC(state);
	    add(pwocC);
            
            pwocA.setBounds(1,1,298,285);
            pwocB.setBounds(1,1,298,285);
            pwocB2.setBounds(1,1,298,285);
            pwocB3.setBounds(1,1,298,285);
            pwocC.setBounds(1,1,298,285);
            
            pwocA.setVisible(true);
            pwocB.setVisible(false);
            pwocB2.setVisible(false);
            pwocB3.setVisible(false);
            pwocC.setVisible(false);
            //pwocA.setBackground(Color.yellow);
            
            //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]==" Refraction Behavior 1"){
		    pwocA.setVisible(true);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(false);
                    pwocB3.setVisible(false);
                    pwocC.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Propagation Data"){
		    pwocA.setVisible(false);
		    pwocB.setVisible(true);
                    pwocB2.setVisible(false);
                    pwocB3.setVisible(false);
		    pwocC.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]==" Propagation Data 2"){
		    pwocA.setVisible(false);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(true);
                    pwocB3.setVisible(false);
		    pwocC.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]==" Refraction Behavior 2"){
		    pwocA.setVisible(false);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(false);
                    pwocB3.setVisible(true);
		    pwocC.setVisible(false);
		}
                else if(ie.getSelectedObjects()[0]==" Field Phasors at (0,0,0)"){
		    pwocA.setVisible(false);
		    pwocB.setVisible(false);
                    pwocB2.setVisible(false);
                    pwocB3.setVisible(false);
		    pwocC.setVisible(true);
		}
	    }
    }	
	
}//ObliqueOutputPanel.java

class ObliqueOutputCanvasA extends Canvas{
	
	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 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;
	    FontMetrics fm;
	    x = 10;
	    y = 25;
	    dx = 75;
	    dxx = 15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",20,20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 15;//fm.getHeight()-1;
	    dyy = dy+5;
	    y+=dyy;
	    g.setColor(Color.red.darker());
	    g.drawString("Incident Angle",x+dxx-5,y);	
	    g.drawString("Effective Refraction Angle",x+2*dx-25,y);
	    y += dy;
	    g.setColor(Color.black);
	    MaestroG.subscripter("\u03b8","i"," = "+MaestroA.rounder(state.theta1*180.0/Math.PI,4)+"\u00ba",g,11,x+dxx,y);
	    //g.setFont(symbfont);
	    //g.drawString("\u03b8",x,y);
	    g.setFont(normalfont);
	    
	    if(state.theta2 != state.theta2){
		g.drawString(" = Undefined",x+2*dx+7,y);
                MaestroG.subscripter("\u03b8","t","",g,11,x+2*dx-5,y);
                //g.setFont(symbfont);
		//g.drawString("\u03b8",x+2*dx,y);
		g.setFont(normalfont);
	    }
	    else{
		g.drawString(" = "+MaestroA.rounder(state.theta2*180.0/Math.PI,4)+"\u00ba",x+2*dx+12,y);
		//g.setFont(symbfont);
		MaestroG.subscripter("\u03b8","t","",g,11,x+2*dx-5,y);
		g.setFont(normalfont);
	    }
	    //g.drawString("\u03b81 = "+MaestroA.rounder(state.theta1*180.0/Math.PI,4)+"\u00ba",x,y);
	    //g.drawString("\u03b82 = "+MaestroA.rounder(state.theta2*180.0/Math.PI,4)+"\u00ba",x+2*dx,y);	
	    g.drawLine(5,y+dyy/3+3,getSize().width-5,y+dyy/3+3); 
	    y += dyy+dyy/4;
	    x = 5;
            dxx = 5;
            
	    g.setColor(Color.red.darker());
	    g.drawString("Electric Field",x,y);
            
            
	    y+= dy;
	    if(state.which == 1){
                g.setColor(Color.yellow);
                g.fillRect(x+dxx-5,y-12,285,15);
            }
	    
            g.setColor(Color.blue.darker());
	    g.drawString("Reflection Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    //temp1 = new Complex(MaestroA.rounder(Complex.Real(state.Reflection_Coef),4),MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),4));
	    //temp2 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),4);
	    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+7,y);
	    g.setFont(symbfont);
	    g.drawString("\u0393",x+2*dx-5,y);
	    g.setFont(normalfont);
            
            
	    y+= dy;
    	    if(state.which == 2){
                g.setColor(Color.yellow);
                g.fillRect(x+dxx-5,y-12,285,15);
            }
            
            g.setColor(Color.blue.darker());
	    g.drawString("Transmission Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    //temp1 = new Complex(MaestroA.rounder(Complex.Real(state.Transmission_Coef),4),MaestroA.rounder(Complex.Imaginary(state.Transmission_Coef),4));
	    //temp3 = MaestroA.rounder(Complex.Real(state.Transmission_Coef),4);
	    
	    temp3 = MaestroA.rounder(Complex.Real(state.Transmission_Coef),4);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.Transmission_Coef),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    //g.drawString(" \u03c4 = "+temp2+"",x+dx+dx,y);
	    g.setFont(symbfont);
            //g.drawString(" \u03c4 = "+temp2+"",x+dx+dx,y);
            MaestroG.SerifSymbFirst(" \u03c4","","",g,12,x+dx+dx-5,y);
	    g.setFont(normalfont);
            g.drawString(" = "+temp2+"",x+dx+dx+7,y);
            
	    g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4); 
	    y += dyy;
	    
            g.setColor(Color.red.darker());
	    g.drawString("Magnetic Field",x,y);
	    
	    y+= dy;
	    
            if(state.which == 3){
                g.setColor(Color.yellow);
                g.fillRect(x+dxx-5,y-12,285,15);
            }
            
            g.setColor(Color.blue.darker());
	    g.drawString("Reflection Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    
            //temp1 = new Complex(MaestroA.rounder(Complex.Real(state.Reflection_Coef),4),MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),4));
	    //temp3 = MaestroA.rounder(-1.0*Complex.Real(state.Reflection_Coef),4);
	    temp3 = MaestroA.rounder(Complex.Real(state.Reflection_CoefH),4);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.Reflection_CoefH),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    g.drawString(" = "+temp2+"",x+dx+dx+7,y);
	    g.setFont(symbfont);
	    g.drawString("\u0393",x+2*dx-5,y);
	    g.setFont(normalfont);

	    
	    y+= dy;
    	    
            if(state.which == 4){
                g.setColor(Color.yellow);
                g.fillRect(x+dxx-5,y-12,285,15);
            }
            
            g.setColor(Color.blue.darker());
	    g.drawString("Transmission Coefficient",x+dxx,y);
	    g.setColor(Color.black);
	    //temp1 = new Complex(MaestroA.rounder(Complex.Real(state.Transmission_Coef),4),MaestroA.rounder(Complex.Imaginary(state.Transmission_Coef),4));
	    //temp3 = MaestroA.rounder(Complex.Real(Complex.Divide(state.wave_impedance2,state.wave_impedance1))*Complex.Real(state.Transmission_Coef),4);
	    ratioZ = Complex.Real(Complex.Divide(state.wave_impedance1,state.wave_impedance2));
	    temp3 = MaestroA.rounder(Complex.Real(state.Transmission_CoefH),4);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.Transmission_CoefH),4);
	    temp2 = new Complex(temp3,temp4);
	    
	    //g.drawString(" \u03c4 = "+temp2+"",x+dx+dx,y);
	    g.setFont(symbfont);
            //g.drawString(" \u03c4 = "+temp2+"",x+dx+dx,y);
            MaestroG.SerifSymbFirst(" \u03c4","","",g,12,x+dx+dx-5,y);
	    g.setFont(normalfont);
	    g.drawString(" = "+temp2+"",x+dx+dx+7,y);
            
	    g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4);
	    
	    y += dyy;
	    
	    g.setColor(Color.red.darker());
	    g.drawString("Power",x,y);
	    
	    y+= dy;
            
            if(state.which == 5){
                g.setColor(Color.yellow);
                g.fillRect(x+dxx-5,y-12,285,15);
            }
            
	    g.setColor(Color.blue.darker());
	    g.drawString("Reflectivity",x+dxx,y);
	    g.setColor(Color.black);
	    //temp1 = new Complex(MaestroA.rounder(Complex.Real(state.Reflection_Coef),4),MaestroA.rounder(Complex.Imaginary(state.Reflection_Coef),4));
	    //temp2 = MaestroA.rounder(Complex.Real(state.Reflection_Coef),4);
	    temp3 = Complex.Magnitude(state.Reflection_Coef);
	    temp4 = temp3*temp3;
	    //g.drawString("R = "+MaestroA.rounder(temp4,6)+"",x+dx+dx,y);
	    g.drawString(" = "+MaestroA.rounder(temp4,6)+"",x+dx+dx+7,y);
	    g.setFont(symbfont);
	    g.drawString("R",x+2*dx-5,y);
	    g.setFont(normalfont);

	    y+= dy;
            
            if(state.which == 6){
                g.setColor(Color.yellow);
                g.fillRect(x+dxx-5,y-12,285,15);
            }
            
    	    g.setColor(Color.blue.darker());
	    g.drawString("Transmissivity",x+dxx,y);
	    g.setColor(Color.black);
	    temp5 = 1.0 - temp4;
	    
	    //g.drawString("T = "+MaestroA.rounder(temp5,6)+"",x+dx+dx,y);
	    g.drawString(" = "+MaestroA.rounder(temp5,6)+"",x+dx+dx+7,y);
	    g.setFont(symbfont);
	    g.drawString("T",x+2*dx-5,y);
	    g.setFont(normalfont);

	    g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4); 
	     
	    y+=dyy;
	    g.setColor(Color.red.darker());
	    g.drawString("Maximum Transmission",x,y);
            g.drawString("Angle",x+dxx,y+13);
            
            g.setFont(normalfont);
            if(state.isPolarizationParallel){
		//g.setColor(Color.black);
		if(state.mu_r1 == state.mu_r2 && state.conductivity2 == 0.0){
		    temp3 = MaestroA.rounder(Math.atan(Math.sqrt(state.epsilon_r2/state.epsilon_r1))*180.0/Math.PI,4);
		    g.drawString(" = "+MaestroA.rounder(temp3,4)+"\u00ba",x+dx+dx+7,y);
		    //g.setFont(symbfont);
		    //g.drawString("\u03b8",x+2*dx,y);
                    MaestroG.subscripter("\u03b8","m","",g,11,x+dx+dx-8,y);
		    g.setFont(normalfont);

		    
		    //g.drawString("\u03b8 = "+temp3+"\u00ba",x+dx+dx,y);
		}
		else{
		    test1 = state.mu_r2*state.epsilon_r1/(state.mu_r1*state.epsilon_r2);
		    test2 = state.epsilon_r1*state.epsilon_r1/(state.epsilon_r2*state.epsilon_r2);
		    test3 = (1.0-test1)/(1.0-test2);
		    
                    //if( Math.abs(test3) < 1.0){
                    if(state.isPolarizationParallel){
			//temp3 = 180.0/Math.PI*Math.asin(Math.sqrt((1.0-test1)/(1.0-test2)));
			//g.drawString(" = "+MaestroA.rounder(temp3,4)+"\u00ba",x+dx+dx+7,y);
			MaestroG.subscripter("\u03b8","m","",g,11,x+dx+dx-8,y);
			g.setFont(normalfont);
			g.drawString(" = "+MaestroA.rounder(state.max/100.0,4)+"\u00ba",x+dx+dx+7,y);
			
		    }
		    else{
			//g.setColor(Color.blue.darker());
			g.drawString(" = Undefined ",x+dx+dx+7,y);
                        MaestroG.subscripter("\u03b8","m","",g,11,x+dx+dx-8,y);
			g.setFont(normalfont);
		    }
		}
	    }
	    else{
		//g.setColor(Color.black);
                g.setFont(normalfont);
		if(state.mu_r1 == state.mu_r2){
		    //g.setColor(Color.blue.darker());
		    g.drawString(" = Undefined ",x+dx+dx+7,y); 
                    MaestroG.subscripter("\u03b8","m","",g,11,x+dx+dx-5,y);
                    g.setFont(normalfont);
		}
		else{
		    test1 = state.mu_r1*state.epsilon_r2/(state.mu_r2*state.epsilon_r1);
		    test2 = state.mu_r1*state.mu_r1/(state.mu_r2*state.mu_r2);
		    test3 = (1.0-test1)/(1.0-test2);
		    if( Math.abs(test3) < 1.0){
			temp3 = 180.0/Math.PI*Math.asin(Math.sqrt((1.0-test1)/(1.0-test2)));
			g.drawString(" = "+MaestroA.rounder(temp3,4)+"\u00ba",x+dx+dx+7,y);
			//g.setFont(symbfont);
			//g.drawString("\u03b8",x+2*dx,y);
                        MaestroG.subscripter("\u03b8","m","",g,11,x+dx+dx-5,y);
			g.setFont(normalfont);
			//g.drawString("\u03b8 = "+MaestroA.rounder(temp3,4)+"\u00ba",x+dx+dx,y);
			
		    }
		    else{
			//g.setColor(Color.blue.darker());
			g.setFont(normalfont);
                        g.drawString(" = Undefined ",x+dx+dx+7,y);
			MaestroG.subscripter("\u03b8","m","",g,11,x+dx+dx-5,y);
			g.setFont(normalfont);
		    }
		}
	    
	    }
	    
	    //g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4); 
	    g.setColor(Color.blue.darker());
	    y += dyy+8;
	    g.drawString("Total Reflection Angle", x, y);
	    g.drawString("(Medium 2 Lossless)", x, y+13);
            
            g.setFont(normalfont);
	    //g.setColor(Color.black);
	    factor1 = Math.sqrt(state.mu_r2*state.epsilon_r2/(state.mu_r1*state.epsilon_r1));
	    if((state.mu_r1*state.epsilon_r1) > (state.mu_r2*state.epsilon_r2)){
		    temp3 = Math.asin(factor1)*180.0/Math.PI;
		    g.drawString(" = "+MaestroA.rounder(temp3,4)+"\u00ba",x+dx+dx+7,y);
		    //g.setFont(symbfont);
		    MaestroG.subscripter("\u03b8","c","",g,11,x+dx+dx-5,y);
                    //g.drawString("\u03b8",x+2*dx,y);
		    g.setFont(normalfont);
		    //g.drawString("\u03b8 = "+MaestroA.rounder(temp3,4)+"\u00ba",x+dx+dx,y);
		}
		else{
		    //g.setColor(Color.blue.darker());
		    g.drawString(" = Undefined ",x+dx+dx+7,y);
                    MaestroG.subscripter("\u03b8","c","",g,11,x+dx+dx-5,y);
			g.setFont(normalfont);
		}
	    //g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4); 
	    
            
	}
}

class ObliqueOutputCanvasB extends Canvas{
	
	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 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){
	    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 = 80;
	    dxx = 55;
            x = 30;
            x2 = 14;
            x3 = x+dxx+170;
            x4 = 14;
	    y = 27;
	    
            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",20,20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 13;//fm.getHeight()-1;
	    dyy = dy;
	    
            
            g.setColor(Color.red.darker());
	    
	    y+= dy;
	    
            //--------------------------------------------- MEDIUM 1
            int fonto = 11;
            double test;
            
            g.setColor(Color.red.darker());
            g.drawString("Wavelength",x4,y);
	    g.drawString("Medium 1",x3-15,y);
	    g.setColor(Color.black);
            
	    y += dy;
	    test = state.wavelength1;
            MaestroG.subscripterSS2("\u03bb","i","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x3,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+1;
            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,x3,y);
            //System.out.println(state.wave_impedance1.Real()+"   "+state.wave_impedance1.Imaginary());
	    Write(g,test,fonto,x,y);
            
            y += dyy+1;
            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,x3-2,y);
	    Write(g,test,fonto,x,y);
            
            y += dy+1;// z-component
            test = state.beta1_z;
            MaestroG.subscripter3("k","i","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
	    Write(g,test,fonto,x,y);
            
	    y += dy+1;// x-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,x3-2,y);
	    Write(g,test,fonto,x,y);
            
            y += 8;
            
            g.setColor(Color.green.darker());
            g.drawLine(10,y,getSize().width-10,y);
            
            
            //------------------------------------ MEDIUM 2
            
            
            y += dyy;
            g.setColor(Color.blue.darker());
            g.drawString("Wavelength",x4,y);
	    g.drawString("Medium 2",x3-15,y);
            g.setColor(Color.black);
            
	    y += dy;
	    test = state.wavelength2;
            MaestroG.subscripterSS2("\u03bb","2","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x3,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+1;
            g.setColor(Color.blue.darker());
            g.drawString("Impedance",x4,y);
	    g.setColor(Color.black);
	    y += dy; 
	    test = state.wave_impedance2.Real();
            test2 = state.wave_impedance2.Imaginary();
            MaestroG.subscripterSS2("\u03b7","2","",g,fonto,x2,y);
	    MaestroG.subscripterSS2(" [ \u03a9",""," ]",g,fonto,x3,y);
	    WriteC(g,test,test2,fonto,x,y);
            
            y += dyy+1;
            g.setColor(Color.blue.darker());
            g.drawString("Bulk wave number",x4,y);
            MaestroG.subscripterSerif("2\u03c0 / \u03bb","2","",g,11,x4+105,y);
	    g.setColor(Color.black);
	    y += dy;// Total beta in bulk material, no interface
	    test = state.beta2bulk;
            MaestroG.subscripter3("\u03b2","2","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
	    Write(g,test,fonto,x,y);
                        
            y += dyy+1;
            g.setColor(Color.blue.darker());
            g.drawString("Refracted wave vector at effective angle",x4,y);
	    g.setColor(Color.black);
            
	    y += dy;// Total beta
	    test = state.beta2;
            MaestroG.subscripter3("k","t","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
	    Write(g,test,fonto,x,y);
            
            y += dy+1;// z-component
            test = state.beta1 * Math.sin(state.theta1);
            MaestroG.subscripter3("k","t","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
	    Write(g,test,fonto,x,y);
            
	    y += dy+1;// x-component
            
            double testangle;
            
            testangle = Math.PI/180.0*state.totalR_angle;
            
            if(state.theta1 < testangle){
                test = state.beta2 * Math.cos(state.theta2);
                MaestroG.subscripter3("k","t","z","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
                Write(g,test,fonto,x,y);
            }
            else if(state.theta1 == testangle){
                test = 0.0;
                MaestroG.subscripter3("k","t","z","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
                Write(g,test,fonto,x,y);
            }
            else if(state.theta1 > testangle){
                
                test = state.beta2 * Math.sqrt((state.mu_r1*state.epsilon_r1)/(state.mu_r2*state.epsilon_r2) *
                      (Math.pow(Math.sin(state.theta1),2.0) - (state.mu_r2*state.epsilon_r2)/(state.mu_r1*state.epsilon_r1)));        
                MaestroG.subscripter3("k","t","z","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m","-1"," ]",g,fonto,x3-2,y);
                WriteI(g,test,fonto,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 WriteI(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);
        }

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


}

class ObliqueOutputCanvasB2 extends Canvas{
	
	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 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){
	    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 = 80;
	    dxx = 15;
            x = 50;
            x2 = 34;
            x3 = x+dxx+150;
            x4 = 20;
	    y = 30;
	    
            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",20,20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 13;//fm.getHeight()-1;
	    dyy = dy;
	    
            
            g.setColor(Color.red.darker());
	    
	    y+= dy;
	    
            //--------------------------------------------- MEDIUM 1
            int fonto = 11;
            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","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+150,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","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+150,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;
            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+150,y);
	    Write(g,test,fonto,x,y);
            */
            
            y += dyy+2;
            g.setColor(Color.red.darker());
            g.drawString("Phase velocity",x4,y);
	    g.setColor(Color.black);
	    y += dy;// Total beta
	    test = state.phase_velocity1;
            MaestroG.subscripter3("v","1","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,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("v","1","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,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("v","1","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,y);
	    if(state.theta1 < Math.PI*0.5){
                Write(g,test,fonto,x,y);
            }
            else{
                g.setFont(normalfont);
                g.drawString("  =  \u221e",x,y);
            }
            
            y += 8;
            
            g.setColor(Color.green.darker());
            g.drawLine(10,y,getSize().width-10,y);
            
            
            //------------------------------------ MEDIUM 2
            
            
            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.wavelength1z;
            MaestroG.subscripter3("\u03bb","2","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+150,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","x","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m",""," ]",g,fonto,x+dxx+150,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+2;
            g.setColor(Color.blue.darker());
            g.drawString("Bulk phase velocity",x4,y);
	    g.setColor(Color.black);
            
	    y += dy;// Total beta
	    test = state.phase_velocity2;
            MaestroG.subscripter3("v","2","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+2;
            g.setColor(Color.blue.darker());
            g.drawString("Phase velocity along effective refraction direction",x4,y);
	    g.setColor(Color.black);
            
	    y += dy;// Total beta
	    test = state.phase_velocity2_eff;
            MaestroG.subscripter3("v","2e","","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,y);
	    Write(g,test,fonto,x,y);
            
            y += dyy+1;
            g.setColor(Color.blue.darker());
            g.drawString("Apparent phase velocities",x4,y);
	    g.setColor(Color.black);
            y += dy+1;// z-component
            
            test = state.phase_velocity2z;
            MaestroG.subscripter3("v","2","z","","",g,fonto,x2,y);
	    MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,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
            
            double testangle;
            
            testangle = Math.PI/180.0*state.totalR_angle;
            
            if(state.theta1 < testangle){
                test = state.phase_velocity2x;
                MaestroG.subscripter3("v","2","x","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,y);
                Write(g,test,fonto,x,y);
            }
            else{
                MaestroG.subscripter3("v","2","x","","",g,fonto,x2,y);
                MaestroG.superscripter(" [ m s","-1"," ]",g,fonto,x+dxx+150,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 WriteI(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 ObliqueOutputCanvasB3 extends Canvas{
	
	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 ObliqueOutputCanvasB3(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, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2;
	    double temp3, temp4, temp5, ratioZ, test1, test2, test3, factor1;
	    FontMetrics fm;
	    x = 10;
	    y = 25;
	    dx = 80;
	    dxx = 15;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    g.setFont(titlefont);
            g.setColor(Color.blue.darker());
	    g.drawString("Output",20,20);

	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 15;//fm.getHeight()-1;
	    dyy = dy+3;
	    y+=dyy;
	    g.setColor(Color.red.darker());
	    g.drawString("Incident Angle",x+dxx-5,y);	
	    g.drawString("Effective Refraction Angle",x+2*dx-25,y);
	    y += dy;
	    g.setColor(Color.black);
	    MaestroG.subscripter("\u03b8","i"," = "+MaestroA.rounder(state.theta1*180.0/Math.PI,4)+"\u00ba",g,11,x+dxx,y);
	    g.setFont(normalfont);
	    
	    if(state.theta2 != state.theta2){
		g.drawString(" = Undefined",x+2*dx+7,y);
                MaestroG.subscripter("\u03b8","t","",g,11,x+2*dx-5,y);
                g.setFont(normalfont);
	    }
	    else{
		g.drawString(" = "+MaestroA.rounder(state.theta2*180.0/Math.PI,4)+"\u00ba",x+2*dx+7,y);
		MaestroG.subscripter("\u03b8","t","",g,11,x+2*dx-5,y);
		g.setFont(normalfont);
	    }
	    g.drawLine(5,y+dyy/3+3,getSize().width-5,y+dyy/3+3); 
	    y += dyy+dyy/2;
	    //------------------------------------------------------------------
            g.setColor(Color.blue.darker());
	    g.drawString("Refraction Parameters",x+dxx-5,y);
	    y+= dy;
            
            g.setColor(Color.black);
	    
            MaestroG.SanSerifSymbFirstSub("sin (\u03b8","i",")",g,12,x+dxx-5,y);
            MaestroG.subscripter("  =  "+MaestroA.rounder(Math.sin(state.theta1),6),"","",g,12,x+dxx+40,y);
    	    y+= dyy;
                        
            temp3 = MaestroA.rounder(Complex.Real(state.singeom2),6);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.singeom2),6);
	    temp2 = new Complex(temp3,temp4);
	    
            MaestroG.SanSerifSymbFirstSub("sin (\u03b8","t",")",g,12,x+dxx-5,y);
            MaestroG.subscripter("  =  "+temp2,"","",g,12,x+dxx+40,y);
    	    y+= dyy;
            
            temp3 = MaestroA.rounder(Complex.Real(state.cosgeom2),6);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.cosgeom2),6);
	    temp2 = new Complex(temp3,temp4);
	    
            MaestroG.SanSerifSymbFirstSub("cos (\u03b8","t",")",g,12,x+dxx-5,y);
            MaestroG.subscripter("  =  "+temp2,"","",g,12,x+dxx+40,y);
            y+= dyy;
            
            Complex prod;
            double prod2;
            prod = Complex.Multiply(new Complex(state.mu_r2,0.0),Complex.Multiply(Complex.Multiply(state.singeom2,state.singeom2),state.epsilon_complex));
            prod2 = Math.sin(state.theta1)*Math.sin(state.theta1)*state.mu_r1*state.epsilon_r1;
	    
            temp3 = MaestroA.rounder(Complex.Real(prod),6);
	    temp4 = MaestroA.rounder(Complex.Imaginary(prod),6);
	    temp2 = new Complex(temp3,temp4);
	    
            MaestroG.subsubsubsubsub2("sin\u00b2","(\u03b8","t",") \u03bc","r2","\u03b5","r2c","","","","","",g,13,x+dxx-17,y);
            
            MaestroG.subsubsubsubsub2("= sin\u00b2","(\u03b8","i",") \u03bc","r1","\u03b5","r1","","","","","",g,13,x+dxx+85,y);
            
           MaestroG.subscripter("= "+MaestroA.rounder(prod2,5),"","",g,12,x+dxx+195,y);
            y+= dy;
             
            //------------------------------------------------------------------
	    g.setFont(normalfont);
            
            g.drawLine(5,y,getSize().width-5,y); 
	    y += dy;
	    
            g.setColor(Color.blue.darker());
	    g.drawString("Medium 2",x+dxx-5,y);
	    y+= dy;
            
            g.setColor(Color.red.darker());
	    g.drawString("Complex Permittivity",x+dxx-5,y);
	    g.setColor(Color.black);
	    temp3 = MaestroA.rounder(Complex.Real(state.epsilon_complex),6);
	    temp4 = MaestroA.rounder(Complex.Imaginary(state.epsilon_complex),6);
	    temp2 = new Complex(temp3,temp4);
	    
            y+= dy;
	    
	   // MaestroG.SanSerifSymbFirstSub("\u03b5","2C","",g,12,x+dxx-5,y);
	    
            //y+= dyy;
	    //MaestroG.subscripter("=  ( "+temp2+" ) \u03b5","0"," [ F/m ]",g,12,x+dxx+20,y);
            MaestroG.subscripter("("+temp2+") \u03b5","0"," F/m",g,12,x+dxx-5,y);
            y+= dyy;
    	    
    	    //------------------------------------------------------------------
            
            g.setColor(Color.red.darker());
	    g.setFont(normalfont);
            g.drawString("Effective Attenuation (z-direction)",x+dxx-5,y);
	    g.setColor(Color.black);
	    
            y+= dy;
	    
            g.setFont(symbfont);
            MaestroG.SerifSymbFirst("\u03b1","","",g,14,x+dxx-5,y);
            g.setFont(normalfont2);
            g.drawString("=  "+MaestroA.rounder(state.pwave,6)+" [ Ne/m ]",x+dxx+7,y);
            
            y+= dyy;
    	    //------------------------------------------------------------------
            g.setColor(Color.red.darker());
	    g.setFont(normalfont);
            g.drawString("Bulk attenuation",x+dxx-5,y);
	    
            g.setColor(Color.black);
	    
            y+= dy;
	    
            g.setFont(symbfont);
            MaestroG.SerifSymbFirst("\u03b1","","",g,14,x+dxx-5,y);
            g.setFont(normalfont2);
            g.drawString("=  "+MaestroA.rounder(state.alpha2,6)+" [ Ne/m ]",x+dxx+7,y);
            //------------------------------------------------------------------
	    
            
            //g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4); 
	    y += dyy;
	    
            g.setColor(Color.red.darker());
	    //g.drawString("Effective ",x,y);
	    
	    y+= dy;
	    
            
            
	}
}


class ObliqueOutputCanvasC extends Canvas{
	
	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 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){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    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;
	    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;
	    
	    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), 1, Color.blue);
                    MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), 1,Color.blue);           
                    MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, 2, Color.blue);
                
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
                    MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto,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),6)+" 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),6)+" H","0"," z","^","  [ V /m ]",g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                   g.setColor(Color.black);
                   MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto,x3,y);
                   y+= dyy;
                   
                   g.setColor(Color.blue);
                   
                    
                        MaestroG.subsubsubUn3("","H","y"," = ( "+Complex.Multiply(R3,new Complex(-1.0,0.0))+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);                        
                    
                    y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                        
                        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(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","E","z"," = ( "+tmpx+" ) H","0"," z","^","  [ V /m ]",g,fonto,x3,y); 
                        
                    
                    y+= dyy+5;
                    
                   g.setColor(Color.black);
                   MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto,x3,y);
                    y+= dyy;
                        
                   g.setColor(Color.blue);
                        
                        MaestroG.subsubsubUn3("","H","y"," = ( "+Complex.Multiply(T3,new Complex(-1.0,0.0))+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                   
                        y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                        Ctempz = Complex.Multiply(Complex.Multiply(state.cosgeom2,TE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply((-1.0),Complex.Multiply(Complex.Multiply(state.singeom2,TE3),state.wave_impedance1));
                        //Ctempx = Complex.Multiply(state.epsilon_complex,Complex.Multiply((-1.0),Complex.Multiply(Complex.Multiply(state.singeom2,TE3),state.wave_impedance1)));
                        //System.out.println(Complex.Multiply(state.singeom2,TE3)+"   singeom2 ="+state.singeom2+"   TE3 = "+TE3);
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","E","z"," = ( "+tmpx+" ) H","0"," 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);
                    
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto,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),6)+" 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),6)+" H","0"," z","^","  [ V /m ]",g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                   g.setColor(Color.black);
                   MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto,x3,y);
                   y+= dyy;
                   
                   g.setColor(Color.blue);
                   
                   MaestroG.subsubsubUn3("","H","y"," = ( "+R3+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    
                   y+= dyy;
                    
                   g.setColor(Color.magenta.darker());
                   
                        
                        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(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","E","z"," = ( "+tmpx+" ) H","0"," z","^","  [ V /m ]",g,fonto,x3,y); 
                    
                    y+= dyy+5;
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                        
                    MaestroG.subsubsubUn3("","H","y"," = ( "+T3+" ) H","0"," y","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                        
                        Ctempz = Complex.Multiply(Complex.Multiply(state.cosgeom2,TE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply((-1.0),Complex.Multiply(Complex.Multiply(state.singeom2,TE3),state.wave_impedance1));
                        //Ctempx = Complex.Multiply(state.epsilon_complex,Complex.Multiply((-1.0),Complex.Multiply(Complex.Multiply(state.singeom2,TE3),state.wave_impedance1)));
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","E","z"," = ( "+tmpx+" ) H","0"," 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;
                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), 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());
                
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto,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),6)+" 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),6)+" E","0"," z","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                        
                    
                    MaestroG.subsubsubUn3("","E","y"," = ( "+Complex.Multiply(R3,new Complex(-1.0,0.0))+" ) E","0"," y","^","  [ V /m ]",g,fonto,x3,y);                        
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                        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(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","H","z"," = ( "+tmpx+" ) E","0"," z","^","  [ A /m ]",g,fonto,x3,y); 
                        
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                    
                    MaestroG.subsubsubUn3("","E","y"," = ( "+Complex.Multiply(T3,new Complex(-1.0,0.0))+" ) E","0"," y","^","  [ V /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    
                    g.setColor(Color.blue);
                    
                        
                        Ctempz = Complex.Divide(Complex.Multiply(state.cosgeom2,TE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply((-1.0),Complex.Divide(Complex.Multiply(state.singeom2,TE3),state.wave_impedance1));
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder(Ctempz.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","H","z"," = ( "+tmpx+" ) E","0"," z","^","  [ A /m ]",g,fonto,x3,y); 
                        
                        /*
                        Ctempx = Complex.Divide(Complex.Multiply(-1.0,TE3),state.wave_impedance2);
                        
                        if(Ctempx.Imaginary()>=0.0){
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder(Ctempx.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsub("","H","//x"," = ( "+tmpx+" ) E","0"," \u00e2","x",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());
                    
                    g.setColor(Color.black);
                    //y+= dyy+5;
                    
                    //
                     
                     MaestroG.subsubsub("Incident Wave","","","","","","",g,fonto,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),6)+" 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),6)+" E","0"," z","^","  [ A /m ]",g,fonto,x3,y);
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Reflected Wave","","","","","","",g,fonto,x3,y);
                    y+= dyy;
                        
                    g.setColor(Color.magenta.darker());
                    
                    MaestroG.subsubsubUn3("","E","y"," = ( "+R3+" ) E","0"," y","^","  [ V /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                    g.setColor(Color.blue);
                    
                        String tmpx, tmpz;
                        Complex Ctempx, Ctempz;
                        Ctempz = Complex.Divide(Complex.Multiply(Math.cos(state.theta1),RE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply((-1.0),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(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","H","z"," = ( "+tmpx+" ) E","0"," z","^","  [ A /m ]",g,fonto,x3,y); 
                    
                    y+= dyy+5;
                    
                    g.setColor(Color.black);
                    MaestroG.subsubsub("Transmitted Wave","","","","","","",g,fonto,x3,y);
                    y+= dyy;
                    
                    g.setColor(Color.magenta.darker());
                        
                    MaestroG.subsubsubUn3("","E","y"," = ( "+T3+" ) E","0"," y","^","  [ V /m ]",g,fonto,x3,y);
                    
                    y+= dyy;
                        
                    g.setColor(Color.blue);
                    
                        Ctempz = Complex.Divide(Complex.Multiply(state.cosgeom2,TE3),state.wave_impedance1);
                        Ctempx = Complex.Multiply((-1.0),Complex.Divide(Complex.Multiply(state.singeom2,TE3),state.wave_impedance1));
                        
                        if(Ctempz.Imaginary()>=0.0){
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        else {
                            tmpz = String.valueOf(MaestroA.rounder((-1.0)*Ctempz.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempz.Imaginary()),6));
                        }
                        
                        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(),6))+" - j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        else {
                            tmpx = String.valueOf(MaestroA.rounder((-1.0)*Ctempx.Real(),6))+" + j "+String.valueOf(MaestroA.rounder(Math.abs(Ctempx.Imaginary()),6));
                        }
                        
                        MaestroG.subsubsubUn3("","H","z"," = ( "+tmpx+" ) E","0"," z","^","  [ A /m ]",g,fonto,x3,y); 
                    
                }
            }
	}
}