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

public class ObliqueCanvasB extends Canvas implements MouseListener{
    private static final Color bgcolor = new Color(200,200,200);
    private static final Color medium1Color = new Color(250,250,250);
    //private static final Color medium2Color = new Color(170,190,190);
    private static final Color medium2Color = new Color(200,220,220);
    
    private static final int LeftMargin=10, RightMargin=10, TopMargin=10, BottomMargin=10;
    private static final Font labfont = new Font("SanSerif",Font.PLAIN,10);
    private static final Font axisfont = new Font("Serif",Font.ITALIC,18);
    public static final Font normalfont = new Font("Sanserif",Font.PLAIN,12);
    public static final Font normalfontB = new Font("Sanserif",Font.BOLD,12);
    public static final Font smallfont = new Font("Sanserif",Font.PLAIN,10);
    public static final Font symbfont = new Font("Serif",Font.PLAIN,12);
    private static final Font labfontbig=new Font("SanSerif",Font.PLAIN,14);
    private static final Font labfontbigI=new Font("Serif",Font.ITALIC,14);
    private double LenVert, LenHor;
    private static final int HGap=10, VGap=10;//for vectors fields.
    private Image im;
    private Graphics buf;
    
    private double vettoreL = 100.0;
    private double extra = 0.1;
    private Oblique_State state;
    private int radius, radius_power, radius_powernew, scale_radius = 150;
    private boolean IsFocusOn, IsPrintOn;
    public boolean Field_Out, Field_Refl_Out, show_normal, show_tang;
    private Color incident = Color.red; 
    public ObliqueCanvasB(Oblique_State state){
	super();
	this.state = state;
	IsFocusOn = false;
        IsPrintOn = false;
        Field_Out = false;
        Field_Refl_Out = true;
        show_normal = true; // selects field normal or parallel to plane of incidence
        show_tang = true; // selects components of the field parallel to plane of 
                          // incidence: true = show tangent component / false = show perp component  
        
	setBackground(bgcolor);
	//Listeners
	this.addMouseListener(this);
        
        radius = getSize().height/2-TopMargin-5*VGap/2-20;
        radius_power = radius * 6/10;
    }

    public void drawCanvas(Graphics g){
	g.setColor(Color.black);
	g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
	drawMedium(g);
	drawAxis(g);
	drawLabels(g);
	drawBackLabels(g);
        {
            drawWaves2(g);
        }
        
        drawY(g);
	
    }
    
    private void drawMedium(Graphics g){/// OK WITH ULABY's BOOK CONVENTIONS
	g.setColor(medium1Color);
	g.fillRect(1,1,3*getSize().width/4-1,getSize().height-2);
	g.setColor(medium2Color);
	g.fillRect(3*getSize().width/4,1,getSize().width/4-1,getSize().height-2);
    }
    
    private void drawAxis(Graphics g){/// OK WITH ULABY's BOOK CONVENTIONS
	g.setColor(Color.black);
	//horizontal axis - z
	g.drawLine(LeftMargin,getSize().height/2,getSize().width-RightMargin-10,getSize().height/2);
	MaestroG.drawArrow( getSize().width-RightMargin-10, getSize().height/2, 7, g);
        
        //vertical axis - x (pointing up in Ulaby's book)
	g.drawLine(3*getSize().width/4,TopMargin,3*getSize().width/4,getSize().height-BottomMargin-10);
        MaestroG.drawArrow( 3*getSize().width/4, TopMargin+10, 5, g);
        
    }

    private void drawY(Graphics g){/// OK WITH ULABY's BOOK CONVENTIONS
	double x1, y1, radiusy, radiusX, radiusdot; 
        x1 = (double)(3*getSize().width/4);
        y1 = (double)(getSize().height/2);
        radiusy = 7.0;
        radiusdot = 2.0;
        radiusX = 8.0;
        Color colorX = new Color(100,100,100);
               
        int rule; float alpha;
        rule = AlphaComposite.SRC_OVER;
        alpha = 1.0f;
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setComposite(AlphaComposite.getInstance(rule, alpha));
        
        MaestroG.fillCircleThick(g, x1, y1,radiusy,1,colorX);
        MaestroG.fillCircleThick(g, x1, y1,radiusy-1.0,1,Color.white);
        MaestroG.fillCircleThick(g, x1, y1,radiusdot,1,colorX);
        
        
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
        
    }
    
    private void drawLabels(Graphics g){
	g.setFont(axisfont);
	FontMetrics fm = g.getFontMetrics();
	String tmp;
	radius = getSize().height/2-TopMargin-scale_radius*VGap/20;
        radius_power = radius*6/10;
        
        Graphics2D g2d = (Graphics2D)g;
        g.setColor(Color.blue.darker());
	
	tmp = "x";
	g.drawString(tmp,3*getSize().width/4-2*fm.stringWidth(tmp)-5,fm.getHeight());
	tmp = "z";
	g.drawString(tmp,getSize().width-RightMargin-fm.stringWidth(tmp)-5,getSize().height/2+fm.getHeight());
	tmp = "y";
	g.drawString(tmp,(3*getSize().width/4+fm.stringWidth(tmp)),getSize().height/2+fm.getHeight());
	
        //g.setFont(normalfontB);
        //g.setColor(Color.red.darker());
	//tmp =  "medium 1";
	//g.drawString(tmp,LeftMargin +10,getSize().height-7*VGap);
	//g.setColor(Color.blue.darker());
	//tmp  = "medium 2";
	//g.drawString(tmp,getSize().width-95,getSize().height-7*VGap);
        
        g.setFont(normalfontB);
        g.setColor(Color.red.darker());
	tmp =  "medium 1";
	//g.drawString(tmp,LeftMargin +10,getSize().height-7*VGap);
        g.drawString(tmp,LeftMargin +10,5+VGap);
	g.setColor(Color.blue.darker());
	tmp  = "medium 2";
	//g.drawString(tmp,getSize().width-95,getSize().height-7*VGap);
        g.drawString(tmp,getSize().width-95,5+VGap);

    }
    
    private void drawBackLabels(Graphics g){/// DONE
	Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        int mediumX, mediumY;
	radius = getSize().height/2-TopMargin-scale_radius*VGap/20;
	FontMetrics fm = g.getFontMetrics();
	//For medium 1
	mediumX = LeftMargin+5;
	mediumY = TopMargin+2*VGap+5;
        //mediumY = getSize().height-15*VGap;
	
        g.setColor(Color.red.darker());
	
        MaestroG.subscripter("\u03b5","r 1"," = "+state.epsilon_r1,g,12,mediumX+7,mediumY); 
	g.setFont(normalfont);   
	fm = g.getFontMetrics();
        
	mediumY += 4*fm.getHeight()/3;
        
	MaestroG.subscripter("\u03bc","r 1"," = "+state.mu_r1,g,12,mediumX+5,mediumY);
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
	mediumY += 4*fm.getHeight()/3;
        MaestroG.subscripter("\u03c3","1"," = 0.0 [S/m]",g,12,mediumX+5,mediumY);  
	g.setFont(normalfontB); 
	fm = g.getFontMetrics();
        
        mediumY = fm.getHeight();
        
        int Xpolar = 280;
        if(state.isPolarizationParallel){
            g.setColor(Color.blue);
            g.drawString("     Parallel",Xpolar,mediumY);
            mediumY += fm.getHeight();
            g.drawString("  Polarization",Xpolar,mediumY);
            mediumY += fm.getHeight();
            g.drawString("       (TM)",Xpolar,mediumY);
        }
        else{
            g.setColor(Color.magenta.darker());
            g.drawString("Perpendicular",Xpolar,mediumY);
            mediumY += fm.getHeight();
            g.drawString("  Polarization",Xpolar,mediumY);
            mediumY += fm.getHeight();
            g.drawString("       (TE)",Xpolar,mediumY);
        }
        
	//For medium 2
	g.setColor(Color.blue.darker());
	mediumX = getSize().width-120;
        mediumY = TopMargin+2*VGap;
        //mediumY = getSize().height-15*VGap;
        
        /*
        MaestroG.subscripter("\u03b5","r 2"," = "+state.epsilon_r2,g,12,mediumX+7,mediumY);    
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
	mediumY += 4*fm.getHeight()/3;
	MaestroG.subscripter("\u03bc","r 2"," = "+state.mu_r2,g,12,mediumX+5,mediumY);
	
        */ 
        
        g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
	mediumY += fm.getHeight();
	//MaestroG.subscripter("  \u03c3","2"," = "+state.conductivity2,g,12,mediumX+5,mediumY); 
        MaestroG.subscripter("\u03c3","2"," \u2192 \u221e  [S/m]", g, 13, mediumX,mediumY);
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
    }
    
    /*
    private void drawBackLabels(Graphics g){/// DONE
	Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        int mediumX, mediumY;
	radius = getSize().height/2-TopMargin-scale_radius*VGap/20;
	FontMetrics fm = g.getFontMetrics();
	//For medium 1
	mediumX = LeftMargin+5;
	//mediumY = TopMargin+2*VGap;
        mediumY = getSize().height-5*VGap;
	
        g.setColor(Color.red.darker());
	
        MaestroG.subscripter("\u03b5","r 1"," = "+state.epsilon_r1,g,12,mediumX+7,mediumY); 
	g.setFont(normalfont);   
	fm = g.getFontMetrics();
        
	mediumY += 4*fm.getHeight()/3;
	MaestroG.subscripter("\u03bc","r 1"," = "+state.mu_r1,g,12,mediumX+5,mediumY);
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
	mediumY += fm.getHeight();
        //MaestroG.subscripter("  \u03c3","1"," = "+state.conductivity1,g,12,mediumX+5,mediumY);  
	g.setFont(normalfontB); 
	fm = g.getFontMetrics();
        
        mediumX = 280;
        mediumY = fm.getHeight();
        if(state.isPolarizationParallel){
            g.setColor(Color.blue);
            g.drawString("     Parallel",mediumX,mediumY);
            mediumY += fm.getHeight();
            g.drawString("  Polarization",mediumX,mediumY);
            mediumY += fm.getHeight();
            g.drawString("       (TM)",mediumX,mediumY);
        }
        else{
            g.setColor(Color.magenta.darker());
            g.drawString("Perpendicular",mediumX,mediumY);
            mediumY += fm.getHeight();
            g.drawString("  Polarization",mediumX,mediumY);
            mediumY += fm.getHeight();
            g.drawString("       (TE)",mediumX,mediumY);
        }
        
	//For medium 2
	g.setColor(Color.blue.darker());
	mediumX = getSize().width-100;
        //mediumY = TopMargin+2*VGap;
        mediumY = getSize().height-5*VGap;
        
        MaestroG.subscripter("\u03b5","r 2"," = "+state.epsilon_r2,g,12,mediumX+7,mediumY);    
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
	mediumY += 4*fm.getHeight()/3;
	MaestroG.subscripter("\u03bc","r 2"," = "+state.mu_r2,g,12,mediumX+5,mediumY);
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
	mediumY += fm.getHeight();
	//MaestroG.subscripter("  \u03c3","2"," = "+state.conductivity2,g,12,mediumX+5,mediumY);  
	g.setFont(normalfont); 
	fm = g.getFontMetrics();
        
    }
    */

        private void drawWaves2(Graphics g){
        double x1, y1, x2, y2;
        int thickness = 6;
            
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
	boolean Scaled_Waves = true;
	radius = 3*getSize().height/4-TopMargin-6*VGap-20;
        radius_powernew = radius*40/100;
        
	//radius = getSize().height/2-TopMargin;
	//drawing in medium 1
	g.setColor(incident);
	//incident ray
	
        double Len = 15;
        
        LenVert = 15.0 * Math.pow(Math.sin(state.theta1),0.5);
        LenHor = 15.0 * Math.pow(Math.cos(state.theta1),0.5);
        double radiusV, fieldL, x2_power, y2_power;
        int thicknessV, radiusH;
        double angolo, angolo2, x2V, y2V, x2E, y2E;
        Color colorV = Color.black;
        Color colorE = Color.magenta.darker();
        Color colorH = Color.blue;
        
        angolo2 = (state.theta1+Math.PI*0.5)+23.0*Math.PI/180.0;
        angolo = (state.theta1+Math.PI*0.5)-23.0*Math.PI/180.0;
        radiusV = radius * 0.4;
        fieldL = 1.1*(radius * 0.4);
        thicknessV = 4;
        radiusH = 16;
        
        
        // center coordinates
          x1 = (double)(3*getSize().width/4);
          y1 = (double)(getSize().height/2);
        
        // coordinates of beginning of incident line
          x2 = (double)(x1-(int)(radius*Math.sin(state.theta1)));
          y2 = (double)(y1-(int)(radius*Math.cos(state.theta1)));
          
          x2_power = (double)(x1-(int)(radius_powernew*Math.sin(state.theta1)));
          y2_power = (double)(y1-(int)(radius_powernew*Math.cos(state.theta1)));
          
          double xo, yo, ango, ango2, rado;
          xo = x1 - 15.0;
          yo = y1 - 50.0;
          rado = Math.sqrt(15.0*15.0 + 50.0*50.0)+5;
          ango = state.theta1*0.5;
          ango2 = state.theta2*0.5;
          
        // coordinates of incident vector tip
          x2V = (double)(x1-(int)(radiusV*Math.sin(state.theta1)));
          y2V = (double)(y1-(int)(radiusV*Math.cos(state.theta1)));
          
          //if(IsFocusOn){MaestroG.drawLineThick(g, x1, y1, x2_power, y2_power, thickness, incident);}
          
        {
	    // CALL ROUTINE TO DRAW REFLECTED WAVE
            drawRefTrans2(g, incident, thickness);
            //if(IsFocusOn){drawScaleRefTrans2(g, incident, thickness);}
	}
	
             int radiusnewx = 50;// these two lines position normal field near interface
             int radiusnewy = 50;
        
        // DRAW INCIDENT WAVE HERE =========================================================
             double y1shiftup = y1-10.0;
             double y1shiftup2 = y1+2*radiusH;
             double xshift = (double)radiusnewx;
             double xmore = 30.0;
             
    	if(state.isPolarizationParallel){ // Parallel Polarization - Incident Wave
                double yshift = 5.0;
                double xshift2 = 12.0;
                Color colorino;
                
                if(show_normal){
                    colorino = colorH;
                }
                else{
                    colorino = colorE;
                }
                g.setColor(colorE);
                MaestroG.subscriptersupBs("E = 0","","","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - 3*radiusnewy));
                g.setColor(colorH);
                MaestroG.subscriptersupBs("H = 0","","","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - 3*radiusnewy + 25));
                
                if(show_normal){
                // make a plus sign
                
                  {
                    MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift-xmore,y1, 
                                    x1+(double)(radiusH/2)-xshift-xmore,y1, 4,colorino);
                    MaestroG.drawLineThick(g, x1-xshift-xmore, y1+(double)(radiusH/2), 
                                    x1-xshift-xmore, y1-(double)(radiusH/2), 4,colorino);
                  }
                // make an equal sign
                    if(state.theta1_deg < (90.0-0.000005)){
                        MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1-(double)(radiusH/2)+2, 
                                    x1-2*radiusH-xshift2, y1-(double)(radiusH/2)+2, 4,colorino);
                        MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1+(double)(radiusH/2)-2, 
                                    x1-2*radiusH-xshift2, y1+(double)(radiusH/2)-2, 4,colorino);
                    }                    
                }
                else{
                    if(show_tang){
                        // make a plus sign
                        {
                            MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift-xmore,y1, 
                                            x1+(double)(radiusH/2)-xshift-xmore,y1,4,colorino);
                            MaestroG.drawLineThick(g, x1-xshift-xmore, y1-(double)(radiusH/2), 
                                            x1-xshift-xmore, y1+(double)(radiusH/2), 4,colorino);
                        }
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1-(double)(radiusH/2)+2, 
                                    x1-2*radiusH-xshift2, y1-(double)(radiusH/2)+2, 4,colorino);
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1+(double)(radiusH/2)-2, 
                                    x1-2*radiusH-xshift2, y1+(double)(radiusH/2)-2, 4,colorino);
                                    
                        }
                    }
                    else{
                        // make a plus sign
                        {
                            MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-2*xshift,y1, 
                                            x1+(double)(radiusH/2)-2*xshift, y1,4,colorino);
                            MaestroG.drawLineThick(g, x1-2*xshift, y1-(double)(radiusH/2), 
                                            x1-2*xshift, y1+(double)(radiusH/2), 4,colorino);
                        }
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1-(double)(radiusH/2)+2, 
                                    x1-2*radiusH-xshift2, y1-(double)(radiusH/2)+2, 4,colorino);
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1+(double)(radiusH/2)-2, 
                                    x1-2*radiusH-xshift2, y1+(double)(radiusH/2)-2, 4,colorino);
                                    
                        }
                    }
                }
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                if(Field_Out){
                        x2E = x1-(radius*Math.sin(state.theta1) - fieldL * Math.cos(state.theta1));
                        y2E = y1-(radius*Math.cos(state.theta1) + fieldL * Math.sin(state.theta1));
                    
                    if(!show_normal){
                        // E field vector
                        
                        if(show_tang){
                            
                            ArrowUP(g, x1-radiusnewx-xmore, y1+radiusnewy+vettoreL, vettoreL, colorE, thicknessV); //*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs2("E","i","//","x","",g,16,
                                                    (int)(x1 - vettoreL-xmore),(int)(y1 + 2*radiusnewy ));
                            
                            MaestroG.subscripterB("0","","",g,36,(int)(x1 + xmore),(int)(y1 + 12 ));
                            
                                                    
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        }
                        else{
                            
                            ArrowLEFT(g, x1-radiusnewx-vettoreL, y1+radiusnewy, vettoreL, colorE, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBss2("\u03b5","1","E","i","//","z","",g,16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 13*radiusnewy/8 ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                                            (int)y1 + (int)(3.0*radiusnewy));
                        }
                        
                        
                    }
                }
                else{
                    x2E = x1-(radius*Math.sin(state.theta1) + fieldL * Math.cos(state.theta1));
                    y2E = y1-(radius*Math.cos(state.theta1) - fieldL * Math.sin(state.theta1));
                    
                    if(!show_normal){
                        // E field vector
                        if(show_tang){
                            
                            ArrowDOWN(g, x1-radiusnewx-xmore, y1+radiusnewy+vettoreL, vettoreL, colorE, thicknessV);//*
                            
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs2("E","i","//","x","",g,16,
                                                    (int)(x1 - vettoreL-xmore),(int)(y1 + 2*radiusnewy ));
                            
                            MaestroG.subscripterB("0","","",g,36,(int)(x1 + xmore),(int)(y1 + 12 ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,
                                                    (int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)( y1 + 3.0*(radiusnewy)));
                            
                        }
                        else{
                            
                            //ArrowDOWN(g, x1-radiusnewx, y1+radiusnewy+vettoreL, vettoreL, colorE, thicknessV);
                            ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1+radiusnewy, vettoreL, colorE, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBss2("\u03b5","1","E","i","//","z","",g,16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 13*radiusnewy/8 ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));

                        }
                    }
                }
            
                
             if(show_normal){    
                //An oval for magnetic field
                
                if(Field_Out){
                        MaestroG.fillCircleThick(g, x1-radiusnewx-xmore, y1+(radiusnewy), (double)radiusH, 2, Color.white);
                
                        MaestroG.fillCircleThick(g, x1-radiusnewx-xmore, y1+radiusnewy, 5.0,2,colorH);
                        MaestroG.drawCircleThick(g, x1-radiusnewx-xmore, y1+radiusnewy, (double)radiusH,4,colorH);
                
                        g.setColor(Color.blue);  
                        
                        // INCIDENT 
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        
                        MaestroG.subscriptersupBs2("H","i","//","y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                     (int)(y1 + radiusnewy));
                        
                }
                else{
                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1+(radiusnewy), (double)radiusH, 2, Color.white);
                
                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2)-xmore,
                                    y1+(radiusnewy)-(double)(radiusH/2),
                                    x1-(radiusnewx) + (double)(radiusH/2)-xmore,
                                    y1+(radiusnewy) + (double)(radiusH/2), 4,colorH);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2)-xmore,
                                    y1+(radiusnewy)-(double)(radiusH/2),
                                    x1-(radiusnewx) - (double)(radiusH/2)-xmore,
                                    y1+(radiusnewy) + (double)(radiusH/2), 4,colorH);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore,
                                    y1+(radiusnewy),
                                    (double)radiusH,4,colorH);
                
                        g.setColor(Color.blue);                   
                        // INCIDENT 
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        
                        
                        MaestroG.subscriptersupBs2("H","i","//","y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                     (int)(y1 + radiusnewy));
                        
               }
            }
        }
             
	else{ // Perpendicular Polarization - Incident Wave
            
                double yshift = 5.0;
                double xshift2 = 12.0;
                Color colorino;
                
                if(show_normal){
                    colorino = colorE;
                }
                else{
                    colorino = colorH;
                }
                
                g.setColor(colorE);
                MaestroG.subscriptersupBs("E = 0","","","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - 3*radiusnewy));
                g.setColor(colorH);
                MaestroG.subscriptersupBs("H = 0","","","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - 3*radiusnewy + 25));
                
                if(show_normal){
                    // make a plus sign
                    MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift-xmore,y1, 
                                    x1+(double)(radiusH/2)-xshift-xmore,y1, 4,colorino);
                    MaestroG.drawLineThick(g, x1-xshift-xmore, y1+(double)(radiusH/2), 
                                    x1-xshift-xmore, y1-(double)(radiusH/2), 4,colorino);
                    // make an equal sign
                    if(state.theta1_deg < (90.0-0.000005)){
                        MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1-(double)(radiusH/2)+2, 
                                    x1-2*radiusH-xshift2, y1-(double)(radiusH/2)+2, 4,colorino);
                        MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1+(double)(radiusH/2)-2, 
                                    x1-2*radiusH-xshift2, y1+(double)(radiusH/2)-2, 4,colorino);
                    }
                }
                else{
                    if(show_tang){
                        // make a plus sign
                        MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift-xmore,y1, 
                                    x1+(double)(radiusH/2)-xshift-xmore,y1, 4,colorino);
                        MaestroG.drawLineThick(g, x1-xshift-xmore, y1+(double)(radiusH/2), 
                                    x1-xshift-xmore, y1-(double)(radiusH/2), 4,colorino);
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1-(double)(radiusH/2)+2, 
                                    x1-2*radiusH-xshift2, y1-(double)(radiusH/2)+2, 4,colorino);
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1+(double)(radiusH/2)-2, 
                                    x1-2*radiusH-xshift2, y1+(double)(radiusH/2)-2, 4,colorino);
                        }
                    }
                    else{
                        // make a plus sign
                        MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-2*xshift+2,y1, 
                                    x1+(double)(radiusH/2)-2*xshift+2,y1, 4,colorino);
                        MaestroG.drawLineThick(g, x1-2*xshift+2, y1+(double)(radiusH/2), 
                                    x1-2*xshift+2, y1-(double)(radiusH/2), 4,colorino);
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1-(double)(radiusH/2)+2, 
                                    x1-2*radiusH-xshift2, y1-(double)(radiusH/2)+2, 4,colorino);
                            MaestroG.drawLineThick(g, x1-radiusH-xshift2, y1+(double)(radiusH/2)-2, 
                                    x1-2*radiusH-xshift2, y1+(double)(radiusH/2)-2, 4,colorino);
                        }
                    }
                }
                
                
                if(Field_Out){
                    g.setColor(Color.blue);
                    x2E = x1-(radius*Math.sin(state.theta1) + fieldL * Math.cos(state.theta1));
                    y2E = y1-(radius*Math.cos(state.theta1) - fieldL * Math.sin(state.theta1));

                    if(!show_normal){// H field vector
                        if(show_tang){
                            
                            //ArrowLEFT(g, x1-radiusnewx-vettoreL, y1+radiusnewy, vettoreL, colorH, thicknessV);
                            ArrowDOWN(g, x1-radiusnewx-xmore, y1+radiusnewy+vettoreL, vettoreL, colorH, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBs("H","i","\u22a5x","",g,16,
                                                    (int)(x1 - vettoreL-xmore),(int)(y1 + 2*radiusnewy ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        }
                        else{
                             
                            //ArrowDOWN(g, x1-radiusnewx, y1+radiusnewy+vettoreL, vettoreL, colorH, thicknessV);
                            ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1+radiusnewy, vettoreL, colorH, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBss("\u03bc","1","H","i","\u22a5z","",g,16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 13*radiusnewy/8 ));
                            
                            MaestroG.subscripterB("0","","",g,36,(int)(x1 + xmore),(int)(y1 + 12 ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        }
                    }
                    
                    
                }
                else{
                    x2E = x1-(radius*Math.sin(state.theta1) - fieldL * Math.cos(state.theta1));
                    y2E = y1-(radius*Math.cos(state.theta1) + fieldL * Math.sin(state.theta1));

                    if(!show_normal){
                        // H field vector
                        if(show_tang){
                            
                            //ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1+radiusnewy, vettoreL, colorH, thicknessV);
                            ArrowUP(g, x1-radiusnewx-xmore, y1+radiusnewy+vettoreL, vettoreL, colorH, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBs("H","i","\u22a5x","",g,16,
                                                    (int)(x1 - vettoreL-xmore),(int)(y1 + 2*radiusnewy ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 + 3.0*(radiusnewy)));
                        }
                        else{
                            
                            //ArrowUP(g, x1-radiusnewx, y1+radiusnewy+vettoreL, vettoreL, colorH, thicknessV);
                            ArrowLEFT(g, x1-radiusnewx-vettoreL, y1+radiusnewy, vettoreL, colorH, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBss("\u03bc","1","H","i","\u22a5z","",g,16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 13*radiusnewy/8 ));
                            
                            MaestroG.subscripterB("0","","",g,36,(int)(x1 + xmore),(int)(y1 + 12 ));
                            
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 + 3.0*(radiusnewy)));
                        }
                    }
                    
                }
                
                //An oval for electric field
                if(Field_Out){
                        if(show_normal){
                            MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1+(radiusnewy), (double)radiusH, 4, Color.white);
                            MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1+(radiusnewy), 5.0,2,colorE);
                            MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore, y1+(radiusnewy), (double)radiusH,4,colorE);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            // INCIDENT 
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx))-85, 
                                                         (int)(y1 + 3.0*(radiusnewy)));

                            MaestroG.subscriptersupBs("E","i","\u22a5y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                         (int)(y1 + radiusnewy));
                            
                            MaestroG.subscripterB("0","","",g,36,(int)(x1 + xmore),(int)(y1 + 12 ));
                        }
                        
                }
                else{
                        if(show_normal){
                            MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1+(radiusnewy), (double)radiusH, 4, Color.white);

                            MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2)-xmore,
                                        y1+(radiusnewy)-(double)(radiusH/2), 
                                        x1-(radiusnewx) + (double)(radiusH/2)-xmore,
                                        y1+(radiusnewy) + (double)(radiusH/2), 4,colorE);
                            MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2)-xmore,
                                        y1+(radiusnewy)-(double)(radiusH/2),
                                        x1-(radiusnewx) - (double)(radiusH/2)-xmore,
                                        y1+(radiusnewy) + (double)(radiusH/2), 4,colorE);
                            MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore,
                                        y1+(radiusnewy),
                                        (double)radiusH,4,colorE);

                            g.setColor(colorE);
                            // INCIDENT 
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            MaestroG.subscripter("Incident Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 + 3.0*(radiusnewy)));

                            MaestroG.subscriptersupBs("E","i","\u22a5y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                         (int)(y1 + radiusnewy));   
                            
                            MaestroG.subscripterB("0","","",g,36,(int)(x1 + xmore),(int)(y1 + 12 ));
                        }
                        
                }
        }
	
    }

    
    //-------------------------------------------------------------------------------------------
    
    public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
    }
    
    //------------------------------------------------------------------------------------------------
    //BOUNDARY CONDITIONS ARROWS
    //------------------------------------------------------------------------------------------------
    //
    
        private void ArrowUP(Graphics g, double xstart, double ystart, double xlength, Color colore, int thickness){
            double LenR = 15.0;
            
            MaestroG.drawLineThick(g,xstart,ystart, xstart, ystart-xlength, thickness, colore);
    
            MaestroG.drawLineThick(g,xstart, ystart - xlength, xstart - LenR * Math.sin(Math.PI/9.0),
                      ystart - xlength + LenR*Math.cos(Math.PI/9.0),thickness,colore);
            MaestroG.drawLineThick(g,xstart, ystart - xlength, xstart + LenR * Math.sin(Math.PI/9.0),
                      ystart - xlength + LenR*Math.cos(Math.PI/9.0),thickness,colore);
        }
        
        private void ArrowDOWN(Graphics g, double xstart, double ystart, double xlength, Color colore, int thickness){
            double LenR = 15.0;
            
            MaestroG.drawLineThick(g,xstart,ystart, xstart, ystart-xlength, thickness, colore);
    
            MaestroG.drawLineThick(g,xstart, ystart, xstart - LenR * Math.sin(Math.PI/9.0),
                      ystart - LenR*Math.cos(Math.PI/9.0),thickness,colore);
            MaestroG.drawLineThick(g,xstart, ystart, xstart + LenR * Math.sin(Math.PI/9.0),
                      ystart - LenR*Math.cos(Math.PI/9.0),thickness,colore);
        }
        
        private void ArrowLEFT(Graphics g, double xstart, double ystart, double xlength, Color colore, int thickness){
            double LenR = 15.0;
            
            MaestroG.drawLineThick(g,xstart,ystart, xstart + xlength, ystart, thickness, colore);
    
            MaestroG.drawLineThick(g,xstart, ystart,xstart + LenR * Math.cos(Math.PI/9.0),
                      ystart - LenR*Math.sin(Math.PI/9.0),thickness,colore);
            MaestroG.drawLineThick(g,xstart, ystart ,xstart + LenR * Math.cos(Math.PI/9.0),
                      ystart + LenR*Math.sin(Math.PI/9.0),thickness,colore);
             
        }
        
        private void ArrowRIGHT(Graphics g, double xstart, double ystart, double xlength, Color colore, int thickness){
            double LenR = 15.0;
            
            MaestroG.drawLineThick(g,xstart,ystart, xstart + xlength, ystart, thickness, colore);
    
            MaestroG.drawLineThick(g,xstart + xlength, ystart ,xstart + xlength - LenR * Math.cos(Math.PI/9.0),
                      ystart - LenR*Math.sin(Math.PI/9.0),thickness,colore);
            MaestroG.drawLineThick(g,xstart + xlength, ystart ,xstart + xlength - LenR * Math.cos(Math.PI/9.0),
                      ystart + LenR*Math.sin(Math.PI/9.0),thickness,colore);
             
        }
        
        
        private void drawRefTrans2(Graphics g, Color colore, int thickness){
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        double x1, y1, x2, y2, x2R, y2R, x2T, y2T;
        
        radius = 3*getSize().height/4-TopMargin-6*VGap-20;
        radius_powernew = radius*40/100;
        double radius_powernew2;
        radius_powernew2 = radius_powernew+13;
        
	g.setColor(incident);
	double Len = 15.0;
        double LenT = 15.0;
        
        double LenR = 15.0 * Math.pow(Math.sin(state.Reflection_Coef.Magnitude()*Math.PI/2.0),0.5);
        
        if(state.Transmission_Coef.Magnitude()>1.0){
            LenT = 15.0;
        }
        else{
            LenT = 15.0 * Math.pow(Math.sin(state.Transmission_Coef.Magnitude()*Math.PI/2.0),0.5);
        }
        double LenTH = 15.0;
        if(state.Transmission_CoefH.Magnitude()>1.0){
            LenTH = 15.0;
        }
        else{
            LenTH = 15.0 * Math.pow(Math.sin(state.Transmission_CoefH.Magnitude()*Math.PI/2.0),0.5);
        }
        
        double radiusV, fieldL, x2_power, y2_power;
        int thicknessV, radiusH;
        double angolo, angolo2, angoloT, angoloT2, x2V, y2V, x2E, y2E;
        Color colorV = Color.black;
        Color colorE = Color.magenta.darker();
        Color colorH = Color.blue;
        
        angolo2 = (state.theta1+Math.PI*0.5)+23.0*Math.PI/180.0;
        angolo = (state.theta1+Math.PI*0.5)-23.0*Math.PI/180.0;
        
        angoloT2 = (state.theta2+Math.PI*0.5)+23.0*Math.PI/180.0;
        angoloT = (state.theta2+Math.PI*0.5)-23.0*Math.PI/180.0;
        
        radiusV = radius * 0.6;
        fieldL = radius * 0.4;
        thicknessV = 4;
        radiusH = 16;
        
        double xmore = 30.0;
        
        // Find Direction of normal field for the Reflected Component
        if(state.isPolarizationParallel){// Parallel Polarization
          //if(state.Reflection_Coef.Imaginary() == 0.0){  
                if(Field_Out){
                    if(state.Reflection_Coef.Real() < 0.0){
                        Field_Refl_Out = true;
                    }
                    else{
                        Field_Refl_Out = false;
                    }
                }
                else{
                    if(state.Reflection_Coef.Real() < 0.0){
                        Field_Refl_Out = false;
                    }
                    else{
                        Field_Refl_Out = true;
                    }
                }
          
        }
        else{// Perpendicular Polarization
            //if(state.Reflection_Coef.Imaginary() == 0.0){ 
                if(Field_Out){
                    if(state.Reflection_Coef.Real() > 0.0){
                        Field_Refl_Out = true;
                    }
                    else{
                        Field_Refl_Out = false;
                    }
                }
                else{
                    if(state.Reflection_Coef.Real() < 0.0){
                        Field_Refl_Out = true;
                    }
                    else{
                        Field_Refl_Out = false;
                    }
                }
          
        }
	  //reflected ray
	  int radiusnewx = 50;// these two lines position normal field near interface
          int radiusnewy = 50;
               
          x1 = (double)(3*getSize().width/4+2);
          y1 = (double)(getSize().height/2-1);
          x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(state.theta1))+2);
          y2 = (double)(getSize().height/2-(int)(radius_powernew*Math.cos(state.theta1))-1);
          x2R = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(state.theta1))+2);
          y2R = (double)(getSize().height/2-(int)((radius+10)*Math.cos(state.theta1))-1);
          
          double vscaled;
          vscaled = state.beta_ratio*((radius+10.0) - radius_powernew2);
              
          if(state.theta1_deg < (state.total_angle+0.00005) && state.theta1_deg > (state.total_angle-0.00005) && state.isPolarizationParallel){ // don'tdraw if not total transmission
          }
          else if(state.wavelength1 == state.wavelength2){
          }
          else
          {
              //MaestroG.drawLineThick(g, x1, y1, x2, y2, thickness, colore);
          
              
          //-------------------------------------------
          }  
	  //transmitted ray
	  if(state.Reflection_Coef.Imaginary() == 0.0){
              
              x1 = (double)(3*getSize().width/4);
              y1 = (double)(getSize().height/2-1);
              x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(state.theta2)));
              y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-1);
              //x2T = (double)(getSize().width/2 +(int)((radius+10)*Math.sin(state.theta2)));
              //y2T = (double)(getSize().height/2+(int)((radius+10)*Math.cos(state.theta2))-1);
              x2T = x1+((radius_powernew2+vscaled)*Math.sin(state.theta2));
              y2T = y1+((radius_powernew2+vscaled)*Math.cos(state.theta2));
              
              //MaestroG.drawLineThick(g, x1, y1, x2, y2, thickness, colore);

          }
          else{
              angoloT2 = (Math.PI)+23.0*Math.PI/180.0;
              angoloT = (Math.PI)-23.0*Math.PI/180.0;
        
              x1 = (double)(3*getSize().width/4);
              y1 = (double)(getSize().height/2-1);
              x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(Math.PI*0.5)));
              y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(Math.PI*0.5))-1);
              x2T = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(Math.PI*0.5)));
              y2T = (double)(getSize().height/2+(int)((radius+10)*Math.cos(Math.PI*0.5))-1);
                x2R = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(state.theta1))+2);
                y2R = (double)(getSize().height/2-(int)((radius+10)*Math.cos(state.theta1))-1);
          
              
              //MaestroG.drawLineThick(g, x1, y1, x2, y2, thickness, colore);

              double xshifto;
              xshifto = radius_powernew2-radius_powernew2*Math.sin(state.theta1);    
          }
          
          //------------------------------------------------------------------------------------
          x2E = x1+(radius_powernew*Math.sin(state.theta1) - fieldL * Math.cos(state.theta1));
          y2E = y1-(radius_powernew*Math.cos(state.theta1) + fieldL * Math.sin(state.theta1));
          
          
          if(state.isPolarizationParallel){ // Parallel Polarization
                double x2EE, y2EE;
              
                //if(state.Reflection_Coef.Imaginary() == 0.0)
                {
                    if(state.theta1_deg < (90.0-0.000005)){
                    // ------------------------ Transmitted Wave
                    /*
                    if(Field_Out){
                        x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-1);
                        x2T = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+10)*Math.cos(state.theta2))-1);

                        x2EE = x1+(radius_powernew2*Math.sin(state.theta2) + fieldL*(state.Transmission_Coef.Magnitude()+extra) * Math.cos(state.theta2));
                        y2EE = y1+(radius_powernew2*Math.cos(state.theta2) - fieldL*(state.Transmission_Coef.Magnitude()+extra) * Math.sin(state.theta2));
                        
                        if(!show_normal){
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            if(show_tang){
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBs2("E","t","//","x","",g,16,
                                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 )+10);
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBss2("\u03b5","2","E","t","//","z","",g,16,
                                                        (int)(x1 + 2*vettoreL/3)+10,(int)(y1 - radiusnewy/2 ));
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                                (int)(y1 - 3.0*(radiusnewy)));
                            }
                            
                            if(show_tang){
                            
                                if(state.Reflection_Coef.Real() > 0.0){
                                    //ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);
                                    ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);//*
                                }
                                else{
                                    //ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);
                                    ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);//*
                                }
                            
                            }
                            else{

                                if(state.Reflection_Coef.Real() > 0.0){
                                    //ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);
                                    ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);
                                }
                                else{
                                    //ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);
                                    ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);
                                }
                            
                            }
                            
                        }
                        else{
                            //An oval for magnetic field

                            MaestroG.fillCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH, 2, Color.white);

                            MaestroG.fillCircleThick(g, x1+radiusnewx+20, y1, 5.0,2,colorH);
                            MaestroG.drawCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH,4,colorH);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(Color.blue);                   
                            
                            // Transmission ONE ACCA
                            FontMetrics fm; int xspace;
                            g.setFont(new Font("SanSerif",Font.PLAIN,14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx), 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                            MaestroG.subscriptersupBs2("H","t","//","y","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - radiusnewy));
                        }
                        
                    }
                    else{
                        x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-1);
                        x2T = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+10)*Math.cos(state.theta2))-1);

                        x2EE = x1+(radius_powernew2*Math.sin(state.theta2) + fieldL*(state.Transmission_Coef.Magnitude()+extra) * Math.cos(state.theta2));
                        y2EE = y1+(radius_powernew2*Math.cos(state.theta2) - fieldL*(state.Transmission_Coef.Magnitude()+extra) * Math.sin(state.theta2));
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        if(!show_normal){
                            // E field vector
                            if(show_tang){
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBs2("E","t","//","x","",g,16,
                                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 )+10);
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBss2("\u03b5","2","E","t","//","z","",g,16,
                                                        (int)(x1 + 2*vettoreL/3)+10,(int)(y1 - radiusnewy/2 ));
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            
                            if(show_tang){
                            
                                if(state.Reflection_Coef.Real() > 0.0){
                                    //ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);
                                    ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);//*
                                }
                                else{
                                    //ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);
                                    ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);//*
                                }
                            
                            }
                            else{
                            
                                if(state.Reflection_Coef.Real() > 0.0){
                                    //ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);
                                    ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);//*
                                }
                                else{
                                    //ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, 4);
                                    ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorE, 4);//*
                                }
                            
                            }
                            
                        }
                        else{
                        //An oval for magnetic field

                         MaestroG.fillCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH, 2, Color.white);

                         MaestroG.drawLineThick(g, x1+radiusnewx-(double)(radiusH/2)+20,
                                        y1-(double)(radiusH/2),
                                        x1+radiusnewx+ (double)(radiusH/2)+20,
                                        y1 + (double)(radiusH/2), 4,colorH);
                         MaestroG.drawLineThick(g, x1+radiusnewx+(double)(radiusH/2)+20,
                                        y1-(double)(radiusH/2),
                                        x1+radiusnewx- (double)(radiusH/2)+20,
                                        y1 + (double)(radiusH/2), 4,colorH);

                         MaestroG.drawCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH,4,colorH);

                        g.setColor(colorH);                   
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        // TWO ACCA
                        FontMetrics fm; int xspace;
                        g.setFont(new Font("SanSerif",Font.PLAIN,14));
                        fm = g.getFontMetrics();
                        xspace = fm.stringWidth("Transmitted Wave");
                        MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                        
                        MaestroG.subscriptersupBs2("H","t","//","y","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                     (int)(y1 - radiusnewy));
                                                     
                        }
                        
                    }
                    */
                }
                }
                
                // REFLECTED WAVE
                
                double y1shiftup = y1-10.0;
                double y1shiftup2 = y1-radiusH-5.0;
                radiusnewx = 50;// these two lines position normal field near interface
                radiusnewy = 50;
                
                if(state.theta1_deg < (state.total_angle+0.00005) && state.theta1_deg > (state.total_angle-0.00005) ){
                }
                else if(state.wavelength1 == state.wavelength2){
                }
                else
                {  
                if(Field_Refl_Out){
                    x2EE = x1+(radius_powernew2*Math.sin(state.theta1) - fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.cos(state.theta1));
                    y2EE = y1-(radius_powernew2*Math.cos(state.theta1) + fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.sin(state.theta1));
                    //double y1shiftup2 = y1-radiusH-5.0;
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    if(!show_normal){
                        // E field vector
                            
                            if(show_tang){
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBs2("E","r","//","x","",g,16,
                                                        (int)(x1 - vettoreL -xmore),(int)(y1 - 2*radiusnewy));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBss2("\u03b5","1","E","r","//","z","",g,16,
                                                        (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                                
                                //MaestroG.subscripter("+","","",g,30,(int)(x1+10),(int)(y1 - 3*radiusnewy/2));
                                //MaestroG.subscripter("+","","",g,30,(int)(x1+10),(int)(y1 - 3*radiusnewy/4));
                                //MaestroG.subscripter("+","","",g,30,(int)(x1+10),(int)(y1)+12);
                                //MaestroG.subscripter("+","","",g,30,(int)(x1+10),(int)(y1 + 3*radiusnewy/2)+12);
                                //MaestroG.subscripter("+","","",g,30,(int)(x1+10),(int)(y1 + 3*radiusnewy/4)+12);
                                g.setColor(Color.red);
                                MaestroG.subscripterB("\u03c1","s","",g,20,(int)(x1 +50),(int)(y1 - 20));
                                MaestroG.drawLineThick(g,x1+22,y1+47+1, x1+22, y1+33+1, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1+40+1, x1+29, y1+40+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1,y1+47+1, x1, y1+33+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1-7,y1+40+1, x1+7, y1+40+1, 4, Color.red);
                                
                                MaestroG.drawLineThick(g,x1+22,y1+87+1, x1+22, y1+73+1, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1+80+1, x1+29, y1+80+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1,y1+87+1, x1, y1+73+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1-7,y1+80+1, x1+7, y1+80+1, 4, Color.red);
                                
                                MaestroG.drawLineThick(g,x1+22,y1-6+1, x1+22, y1+8+1, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1+1, x1+29, y1+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1,y1-6+1, x1, y1+8+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1-7,y1+1, x1+7, y1+1, 4, Color.red);
                                
                                MaestroG.drawLineThick(g,x1+22,y1-47+1, x1+22, y1-33+1, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1-40+1, x1+29, y1-40+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1,y1-47+1, x1, y1-33+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1-7,y1-40+1, x1+7, y1-40+1, 4, Color.red);
                                
                                MaestroG.drawLineThick(g,x1+22,y1-87+1, x1+22, y1-73+1, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1-80+1, x1+29, y1-80+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1,y1-87+1, x1, y1-73+1, 4, Color.red);
                                //MaestroG.drawLineThick(g,x1-7,y1-80+1, x1+7, y1-80+1, 4, Color.red);
                            }
                        
                        if(show_tang){
                            
                            if(state.Reflection_Coef.Real() > 0.0){
                                //ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowDOWN(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorE, 4);//*
                            }
                            else{
                                //ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowDOWN(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorE, 4);//*
                            }
                            
                        }
                        else{
                            
                            if(state.Reflection_Coef.Real() > 0.0){
                                //ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);
                            }
                            else{
                                //ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);
                            }
                            
                        }
                        
                    }
                    else{
                        //An oval for magnetic field

                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1-radiusnewy, (double)radiusH, 2, Color.white);

                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1-radiusnewy, 5.0,2,colorH);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore, y1-radiusnewy, (double)radiusH,4,colorH);

                        g.setColor(Color.blue);                   
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        // FIVE ACCA
                        MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                        MaestroG.subscriptersupBs2("H","r","//","y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                             (int)((0.96 * y1) - (radiusnewy)));
                        
                        //SURFACE CURRENT
                        ArrowUP(g, x1, y1+60, 120, Color.red, 4);
                        MaestroG.subscripterB("J","S","",g,18,(int)(1.05 * x1),(int)(y1 - 30));
                    }
                    
                }
                else{ // FIELD IN
                    x2EE = x1+(radius_powernew2*Math.sin(state.theta1) + fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.cos(state.theta1));
                    y2EE = y1-(radius_powernew2*Math.cos(state.theta1) - fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.sin(state.theta1));
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    if(!show_normal){
                        // E field vector
                        
                            if(show_tang){
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBs2("E","r","//","x","",g,16,
                                                        (int)(x1 - vettoreL-xmore),(int)(y1 - 2*radiusnewy ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBss2("\u03b5","1","E","r","//","z","",g,16,
                                                        (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                                
                                // Surface charge (negative)
                                g.setColor(Color.red);
                                MaestroG.subscripterB("\u03c1","s","",g,20,(int)(x1 +50),(int)(y1 - 20));
                                //MaestroG.drawLineThick(g,x1+22,y1+47, x1+22, y1+33, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1+40+1, x1+29, y1+40+1, 4, Color.red);
                                
                                //MaestroG.drawLineThick(g,x1+22,y1+87, x1+22, y1+73, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1+80+1, x1+29, y1+80+1, 4, Color.red);
                                
                                //MaestroG.drawLineThick(g,x1+22,y1-7, x1+22, y1+7, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1+1, x1+29, y1+1, 4, Color.red);
                                //MaestroG.drawCircleThick(g, x1+22, y1, 10.0, 2, Color.black);
                                
                                //MaestroG.drawLineThick(g,x1+22,y1-47, x1+22, y1-33, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1-40+1, x1+29, y1-40+1, 4, Color.red);
                                
                                //MaestroG.drawLineThick(g,x1+22,y1-87, x1+22, y1-73, 4, Color.red);
                                MaestroG.drawLineThick(g,x1+15,y1-80+1, x1+29, y1-80+1, 4, Color.red);
                            }
                            
                        if(show_tang){
                             
                            if(state.Reflection_Coef.Real() > 0.0){
                                //ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowUP(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorE, 4);//*
                            }
                            else{
                                //ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowUP(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorE, 4);//*
                            }
                            
                        }
                        else{
                            
                            if(state.Reflection_Coef.Real() < 0.0){
                                //ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);//*
                            }
                            else{
                                //ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, 4);
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, 4);//*
                            }
                            
                        }
                        
                    }
                    else{
                        //An oval for magnetic field

                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1-radiusnewy, (double)radiusH, 2, Color.white);

                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2)-xmore,
                                        y1-radiusnewy-(double)(radiusH/2),
                                        x1-(radiusnewx) + (double)(radiusH/2)-xmore,
                                        y1-radiusnewy + (double)(radiusH/2), 4,colorH);
                         MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2)-xmore,
                                        y1-radiusnewy-(double)(radiusH/2),
                                        x1-(radiusnewx) - (double)(radiusH/2)-xmore,
                                        y1-radiusnewy + (double)(radiusH/2), 4,colorH);

                        MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore, y1-radiusnewy, (double)radiusH,4,colorH);

                        g.setColor(colorH);                   

                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        // SIX ACCA
                        MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                        MaestroG.subscriptersupBs2("H","r","//","y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                             (int)((0.96 * y1) - (radiusnewy)));
                        
                        //SURFACE CURRENT
                        ArrowDOWN(g, x1, y1+60, 120, Color.red, 4);
                        MaestroG.subscripterB("J","S","",g,18,(int)(1.05 * x1),(int)(y1 - 30));
                    }
                    
                }
              }
                
        }
	else{  // Perpendicular Polarization
               
                double x2EE, y2EE;
                
                //if(state.Reflection_Coef.Imaginary() == 0.0)
                {
                    if(state.theta1_deg < (90.0-0.000005)){
                    //------------------ transmitted field
                    /*
                    if(Field_Out){
                        x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-1);
                        x2T = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+10)*Math.cos(state.theta2))-1);

                        x2EE = x1+(radius_powernew2*Math.sin(state.theta2) + fieldL*(state.Transmission_CoefH.Magnitude()+extra) * Math.cos(state.theta2));
                        y2EE = y1+(radius_powernew2*Math.cos(state.theta2) - fieldL*(state.Transmission_CoefH.Magnitude()+extra) * Math.sin(state.theta2));
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

                        if(!show_normal){
                            // H field vector
                            if(show_tang){
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBs("H","t","\u22a5x","",g,16,
                                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 )+10);
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBss("\u03bc","2","H","t","\u22a5z","",g,16,
                                                        (int)(x1 + 2*vettoreL/3)+10,(int)(y1 - radiusnewy/2 ));
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            
                            if(show_tang){
                                    //ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorH, 4);
                                    ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorH, 4); //*
                            }
                            else{
                                    //ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorH, 4); 
                                    ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorH, 4);//*
                            }
                        }
                        else{
                            //An oval for electric field
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);
                            FontMetrics fm; int xspace;
                            g.setFont(new Font("SanSerif",Font.PLAIN,14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx), 
                                                         (int)(y1 - 3.0*(radiusnewy)));


                            MaestroG.fillCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH, 2, Color.white);

                            MaestroG.fillCircleThick(g, x1+radiusnewx+20, y1, 5.0,2,colorE);
                            MaestroG.drawCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH,4,colorE);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs("E","t","\u22a5y","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - radiusnewy));
                        }
                        
                    }
                    else{
                        x2 = (double)(3*getSize().width/4 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-1);
                        x2T = (double)(3*getSize().width/4 +(int)((radius+10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+10)*Math.cos(state.theta2))-1);
                        // WORK ON THESE
                        x2EE = x1+(radius_powernew2*Math.sin(state.theta2) + fieldL*(state.Transmission_CoefH.Magnitude()+extra) * Math.cos(state.theta2));
                        y2EE = y1+(radius_powernew2*Math.cos(state.theta2) - fieldL*(state.Transmission_CoefH.Magnitude()+extra) * Math.sin(state.theta2));
                        
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);    
                        
                        if(!show_normal){
                            if(show_tang){
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBs("H","t","\u22a5x","",g,16,
                                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 )+10);
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 +radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBss("\u03bc","2","H","t","\u22a5z","",g,16,
                                                        (int)(x1 + 2*vettoreL/3)+10,(int)(y1 - radiusnewy/2 ));
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            
                            if(show_tang){
                                    //ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorH, 4);    
                                    ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorH, 4);//*
                            }
                            else{
                                    //ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorH, 4);
                                    ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorH, 4);//*
                            }
                        }
                        else{
                            //An oval for electric field
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);
                            FontMetrics fm; int xspace;
                            g.setFont(new Font("SanSerif",Font.PLAIN,14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,14,(int)(x1 + radiusnewx), 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                             MaestroG.fillCircleThick(g, x1+radiusnewx+20, y1, (double)radiusH, 2, Color.white);

                             MaestroG.drawLineThick(g, x1+radiusnewx-(double)(radiusH/2)+20,
                                            y1-(double)(radiusH/2),
                                            x1+radiusnewx+(double)(radiusH/2)+20,
                                            y1 + (double)(radiusH/2), 4,colorE);
                             MaestroG.drawLineThick(g, x1+radiusnewx+(double)(radiusH/2)+20,
                                            y1-(double)(radiusH/2),
                                            x1+radiusnewx-(double)(radiusH/2)+20,
                                            y1 + (double)(radiusH/2), 4,colorE);

                             MaestroG.drawCircleThick(g, x1+radiusnewx+20, y1,(double)radiusH,4,colorE);
                             g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs("E","t","\u22a5y","",g,16,(int)(x1 + 3*radiusnewx/2), 
                                                         (int)(y1 - radiusnewy));
                        }
                    }
                    */
                }
                }
                
                //Reflected Wave
                if(Field_Refl_Out){
                    x2EE = x1+(radius_powernew2*Math.sin(state.theta1) + fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.cos(state.theta1));
                    y2EE = y1-(radius_powernew2*Math.cos(state.theta1) - fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.sin(state.theta1));
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    if(!show_normal){
                        // H field vector
                        
                            if(show_tang){
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBs("H","r","\u22a5x","",g,16,
                                                        (int)(x1 - vettoreL-xmore),(int)(y1 - 2*radiusnewy ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                                
                                // Surface Current
                                MaestroG.fillCircleThick(g, x1,y1-3*(radiusnewy)/2,(double)radiusH, 2, Color.white);
                                MaestroG.drawLineThick(g, x1-(double)(radiusH/2),y1-3*(radiusnewy)/2-(double)(radiusH/2),
                                        x1 + (double)(radiusH/2),y1-3*(radiusnewy)/2 + (double)(radiusH/2), 4,Color.red);
                                MaestroG.drawLineThick(g, x1+(double)(radiusH/2),y1-3*(radiusnewy)/2-(double)(radiusH/2),
                                        x1 - (double)(radiusH/2),y1-3*(radiusnewy)/2 + (double)(radiusH/2), 4,Color.red);
                                MaestroG.drawCircleThick(g, x1,y1-3*(radiusnewy)/2,(double)radiusH, 4, Color.red);
                                
                                MaestroG.fillCircleThick(g, x1,y1+3*(radiusnewy)/2,(double)radiusH, 2, Color.white);
                                MaestroG.drawLineThick(g, x1-(double)(radiusH/2),y1+3*(radiusnewy)/2-(double)(radiusH/2),
                                        x1 + (double)(radiusH/2),y1+3*(radiusnewy)/2 + (double)(radiusH/2), 4,Color.red);
                                MaestroG.drawLineThick(g, x1+(double)(radiusH/2),y1+3*(radiusnewy)/2-(double)(radiusH/2),
                                        x1 - (double)(radiusH/2),y1+3*(radiusnewy)/2 + (double)(radiusH/2), 4,Color.red);
                                MaestroG.drawCircleThick(g, x1,y1+3*(radiusnewy)/2,(double)radiusH, 4, Color.red);
                                
                                //MaestroG.fillCircleThick(g, x1,y1-4*(radiusnewy),(double)radiusH, 2, Color.white);
                                //MaestroG.drawLineThick(g, x1-(double)(radiusH/2),y1-4*(radiusnewy)-(double)(radiusH/2),
                                //        x1 + (double)(radiusH/2),y1-4*(radiusnewy) + (double)(radiusH/2), 4,Color.red);
                                //MaestroG.drawLineThick(g, x1+(double)(radiusH/2),y1-4*(radiusnewy)-(double)(radiusH/2),
                                //        x1 - (double)(radiusH/2),y1-4*(radiusnewy) + (double)(radiusH/2), 4,Color.red);
                                //MaestroG.drawCircleThick(g, x1,y1-4*(radiusnewy),(double)radiusH, 4, Color.red);
                                
                                //MaestroG.fillCircleThick(g, x1,y1+4*(radiusnewy),(double)radiusH, 2, Color.white);
                                //MaestroG.drawLineThick(g, x1-(double)(radiusH/2),y1+4*(radiusnewy)-(double)(radiusH/2),
                                //        x1 + (double)(radiusH/2),y1+4*(radiusnewy) + (double)(radiusH/2), 4,Color.red);
                                //MaestroG.drawLineThick(g, x1+(double)(radiusH/2),y1+4*(radiusnewy)-(double)(radiusH/2),
                                //        x1 - (double)(radiusH/2),y1+4*(radiusnewy) + (double)(radiusH/2), 4,Color.red);
                                //MaestroG.drawCircleThick(g, x1,y1+4*(radiusnewy),(double)radiusH, 4, Color.red);
                                
                                
                                //MaestroG.subscripterB("J","S","",g,18,(int)(1.05 * x1),(int)(y1-2*(radiusnewy)-(double)(radiusH/2)));
                                MaestroG.subscripterB("J","S","",g,18,(int)(1.05 * x1),(int)(y1+2*(radiusnewy)+2*(double)(radiusH/2)));
                            }
                            else{
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBss("\u03bc","1","H","r","\u22a5z","",g,16,
                                                        (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                            }
                        
                        
                        
                        if(show_tang){
                             
                            if(state.Reflection_CoefH.Real() > 0.0){
                                //ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowUP(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                            else{
                                //ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowUP(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                            
                        }
                        else{
                            
                            if(state.Reflection_CoefH.Real() < 0.0){
                                //ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                            else{
                                //ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                            
                        }
                    }
                    else{
                        //An oval for electric field

                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1-(radiusnewy), (double)radiusH, 2, Color.white);

                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore, y1-(radiusnewy), 5.0,2,colorE);

                        MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore, y1-(radiusnewy), (double)radiusH,4,colorE);
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(colorE);                   
                        MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                        MaestroG.subscriptersupBs("E","r","\u22a5y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                             (int)((0.96 * y1) - (radiusnewy)));

                    }
                    
                }
                else{
                    x2EE = x1+(radius_powernew2*Math.sin(state.theta1) - fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.cos(state.theta1));
                    y2EE = y1-(radius_powernew2*Math.cos(state.theta1) + fieldL*(state.Reflection_Coef.Magnitude()+extra) * Math.sin(state.theta1));
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    if(!show_normal){
                            if(show_tang){
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBs("H","r","\u22a5x","",g,16,
                                                        (int)(x1 - vettoreL-xmore),(int)(y1 - 2*radiusnewy ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                                
                                // Surface current
                                MaestroG.fillCircleThick(g, x1, y1-3*(radiusnewy)/2, (double)radiusH, 2, Color.white);
                                MaestroG.fillCircleThick(g, x1, y1-3*(radiusnewy)/2, 5.0,2,Color.red);
                                MaestroG.drawCircleThick(g, x1, y1-3*(radiusnewy)/2, (double)radiusH,4,Color.red);
                                
                                MaestroG.fillCircleThick(g, x1, y1+3*(radiusnewy)/2, (double)radiusH, 2, Color.white);
                                MaestroG.fillCircleThick(g, x1, y1+3*(radiusnewy)/2, 5.0,2,Color.red);
                                MaestroG.drawCircleThick(g, x1, y1+3*(radiusnewy)/2, (double)radiusH,4,Color.red);
                                
                                //MaestroG.fillCircleThick(g, x1, y1-4*(radiusnewy), (double)radiusH, 2, Color.white);
                                //MaestroG.fillCircleThick(g, x1, y1-4*(radiusnewy), 5.0,2,Color.red);
                                //MaestroG.drawCircleThick(g, x1, y1-4*(radiusnewy), (double)radiusH,4,Color.red);
                                
                                //MaestroG.fillCircleThick(g, x1, y1+4*(radiusnewy), (double)radiusH, 2, Color.white);
                                //MaestroG.fillCircleThick(g, x1, y1+4*(radiusnewy), 5.0,2,Color.red);
                                //MaestroG.drawCircleThick(g, x1, y1+4*(radiusnewy), (double)radiusH,4,Color.red);
                                
                                //MaestroG.subscripterB("J","S","",g,18,(int)(1.05 * x1),(int)(y1-2*(radiusnewy)-(double)(radiusH/2)));
                                MaestroG.subscripterB("J","S","",g,18,(int)(1.05 * x1),(int)(y1+2*(radiusnewy)+2*(double)(radiusH/2)));
                            }
                            else{
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBss("\u03bc","1","H","r","\u22a5z","",g,16,
                                                        (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                                MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                     (int)(y1 - 3.0*(radiusnewy)));
                            }
                        
                        if(show_tang){
                             
                            if(state.Reflection_CoefH.Real() > 0.0){
                                //ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowDOWN(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                            else{
                                //ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowDOWN(g, x1-radiusnewx-xmore, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                        }
                        else{
                            
                            if(state.Reflection_CoefH.Real() < 0.0){
                                //ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }
                            else{
                                //ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, 4);
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, 4);//*
                            }   
                        }
                    }
                    else{
                        //An oval for electric field

                        MaestroG.fillCircleThick(g, x1-(radiusnewx)-xmore,
                                            y1-(radiusnewy),
                                            (double)radiusH, 2, Color.white);

                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2)-xmore,
                                        y1-(radiusnewy)-(double)(radiusH/2),
                                        x1-(radiusnewx) + (double)(radiusH/2)-xmore,
                                        y1-(radiusnewy) + (double)(radiusH/2), 4,colorE);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2)-xmore,
                                        y1-(radiusnewy)-(double)(radiusH/2),
                                        x1-(radiusnewx) - (double)(radiusH/2)-xmore,
                                        y1-(radiusnewy) + (double)(radiusH/2), 4,colorE);

                        MaestroG.drawCircleThick(g, x1-(radiusnewx)-xmore, y1-(radiusnewy), (double)radiusH,4,colorE);
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(colorE);                   
                        MaestroG.subscripter("Reflected Wave","","",g,14,(int)((0.9 * x1) - (radiusnewx)-xmore)-85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                        MaestroG.subscriptersupBs("E","r","\u22a5y","",g,16,(int)(x1 - 5*radiusnewx/2-xmore), 
                                                             (int)((0.96 * y1) - (radiusnewy)));
                    }
                }
         }
    }
        
    //-------------------------------------------------------------------------------------------------
    
    public void update(Graphics g){
	paint(g);
    }
    
    public void mouseClicked(MouseEvent evt){
        if(IsFocusOn){
            IsFocusOn = false;
            repaint();
        }
        else{
            IsFocusOn = true;
            repaint();
        }
    }
    public void mouseEntered(MouseEvent evt){
	IsPrintOn = true;
	repaint();
    }
    public void mouseExited(MouseEvent evt){
	IsPrintOn = false;
	repaint();
    }
    public void mousePressed(MouseEvent evt){}
    public void mouseReleased(MouseEvent evt){}
}
