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 int LeftMargin, RightMargin, TopMargin, BottomMargin;
    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 int HGap, VGap;//for vectors fields.
    private Image im;
    private Graphics buf;
    
    private double vettoreL;
    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-state.s20;
        radius_power = radius * 6/10;
        LeftMargin = state.s10;
        RightMargin = state.s10;
        TopMargin = state.s10;
        BottomMargin = state.s10;
        HGap = state.s10;
        VGap = state.s10;
        vettoreL = (double)state.s100;
    }

    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,getSize().width/2-1,getSize().height-2);
	g.setColor(medium2Color);
	g.fillRect(getSize().width/2,1,getSize().width/2-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 - state.s10,getSize().height/2);
	MaestroG.drawArrow( getSize().width-RightMargin - state.s10, getSize().height/2, 7, g);
        
        //vertical axis - x (pointing up in Ulaby's book)
	g.drawLine(getSize().width/2,TopMargin,getSize().width/2,getSize().height-BottomMargin - state.s10);
        MaestroG.drawArrow( getSize().width/2, TopMargin + 10, 5, g);
    }

    private void drawY(Graphics g){ // OK WITH ULABY's BOOK CONVENTIONS
	double x1, y1, radiusy, radiusX, radiusdot; 
        x1 = (double)(getSize().width/2);
        y1 = (double)(getSize().height/2);
        radiusy = (double)state.s7;
        radiusdot = (double)state.s2;
        radiusX = (double)state.s8;
        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,state.s1,colorX);
        MaestroG.fillCircleThick(g, x1, y1,radiusy-(double)state.s1,state.s1,Color.white);
        MaestroG.fillCircleThick(g, x1, y1,radiusdot,state.s1,colorX); 
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
    }
    
    private void drawLabels(Graphics g){
	g.setFont(new Font("Serif",Font.ITALIC,state.font18));
	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.black);
	tmp = "x";
	g.drawString(tmp,getSize().width/2-2*fm.stringWidth(tmp)-state.s5,fm.getHeight());
	tmp = "z";
	g.drawString(tmp,getSize().width-RightMargin-fm.stringWidth(tmp) - state.s5,getSize().height/2+fm.getHeight());
        g.drawString(tmp,getSize().width-RightMargin-fm.stringWidth(tmp) - state.s5,getSize().height/2+fm.getHeight());
	tmp = "y";
	g.drawString(tmp,(getSize().width/2+fm.stringWidth(tmp)),getSize().height/2+fm.getHeight());
        g.setFont(new Font("Sanserif",Font.BOLD,state.s12));
        g.setColor(Color.red.darker());
	tmp =  "medium 1";
	g.drawString(tmp,LeftMargin + state.s10,getSize().height-7*VGap);
	g.setColor(Color.blue.darker());
	tmp  = "medium 2";
	g.drawString(tmp,getSize().width - state.s95,getSize().height-7*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 + state.s5;
	mediumY = getSize().height - 5*VGap;
	g.setColor(Color.red.darker());
	MaestroG.subscripter("\u03b5","r 1"," = "+state.epsilon_r1,g,state.font13,mediumX + state.s7,mediumY); 
	
        g.setFont(new Font("Sanserif",Font.PLAIN,state.s12));
	fm = g.getFontMetrics();
	mediumY += 4*fm.getHeight()/3;
	MaestroG.subscripter("\u03bc","r 1"," = "+state.mu_r1,g,state.font13,mediumX + state.s5,mediumY);
	g.setFont(new Font("Sanserif",Font.PLAIN,state.s12));
	fm = g.getFontMetrics();
        
	mediumY += fm.getHeight();
        //MaestroG.subscripter("  \u03c3","1"," = "+state.conductivity1,g,state.font13,mediumX + state.s5,mediumY);  
	g.setFont(new Font("Sanserif",Font.BOLD,state.s12));
	fm = g.getFontMetrics();
        
        mediumY = fm.getHeight();
        int Xpolar = state.s100+state.s50;
        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-state.s100;
        //mediumY = TopMargin+2*VGap;
        mediumY = getSize().height-5*VGap;
        
        MaestroG.subscripter("\u03b5","r 2"," = "+state.epsilon_r2,g,state.font13,mediumX+state.s7,mediumY);    
	g.setFont(new Font("Sanserif",Font.PLAIN,state.s12));
	fm = g.getFontMetrics();
        
	mediumY += 4*fm.getHeight()/3;
	MaestroG.subscripter("\u03bc","r 2"," = "+state.mu_r2,g,state.font13,mediumX+state.s5,mediumY);
	g.setFont(new Font("Sanserif",Font.PLAIN,state.s12)); 
	fm = g.getFontMetrics();
        
	mediumY += fm.getHeight();
	//MaestroG.subscripter("  \u03c3","2"," = "+state.conductivity2,g,state.font13,mediumX+5,mediumY);  
	g.setFont(new Font("Sanserif",Font.PLAIN,state.s12)); 
	fm = g.getFontMetrics();
    }

        private void drawWaves2(Graphics g){
        double x1, y1, x2, y2;
        int thickness = state.s6;
            
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	boolean Scaled_Waves = true;
	radius = getSize().height/2-TopMargin-6*VGap-state.s20;
        radius_powernew = radius*40/100;
        //radius = getSize().height/2-TopMargin;
	
        //drawing in medium 1
	g.setColor(incident);
	//incident ray
        double Len = (double)state.s15;
        LenVert = ((double)state.s15) * Math.pow(Math.sin(state.theta1),0.5);
        LenHor = ((double)state.s15) * 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 = state.s4;
        radiusH = state.s16;
        // center coordinates
        x1 = (double)(getSize().width/2);
        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 - (double)state.s15;
        yo = y1 - (double)state.s50;
        rado = state.sfactor*(Math.sqrt(15.0*15.0 + 50.0*50.0) + state.s5);
        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 AND TRANSMITTED WAVE
            drawRefTrans2(g, incident, thickness);
            //if(IsFocusOn){drawScaleRefTrans2(g, incident, thickness);}
	}
	
             int radiusnewx = state.s50;// these two lines position normal field near interface
             int radiusnewy = state.s50;
        
        // DRAW INCIDENT WAVE HERE =========================================================
             double y1shiftup = y1-(double)state.s10;
             double y1shiftup2 = y1+2*radiusH;
             double xshift = (double)radiusnewx;
             
    	if(state.isPolarizationParallel){ // Parallel Polarization - Incident Wave
                double yshift = (double)state.s5;
                double xshift2 = (double)state.s5;
                Color colorino;
                
                if(show_normal){
                    colorino = colorH;
                }
                else{
                    colorino = colorE;
                }
                
                if(show_normal){
                // make a plus sign
                
                  if(state.theta1_deg < (state.total_angle+0.00005) && state.theta1_deg > (state.total_angle-0.00005) && state.isPolarizationParallel){}
                  else{
                    MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift+state.s2,y1, 
                                    x1+(double)(radiusH/2)-xshift+state.s2,y1, state.s4,colorino);
                    MaestroG.drawLineThick(g, x1-xshift+state.s2, y1+(double)(radiusH/2), 
                                    x1-xshift+state.s2, y1-(double)(radiusH/2), state.s4,colorino);
                  }
                // make an equal sign
                    if(state.theta1_deg < (90.0-0.000005)){
                        MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, 
                                    x1+2*radiusH+xshift2, y1-(double)(radiusH/2)+2, state.s4,colorino);
                        MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, 
                                    x1+2*radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, state.s4,colorino);
                    }                    
                }
                else{
                    if(show_tang){
                        // make a plus sign
                        if(state.theta1_deg < (state.total_angle+0.00005) && state.theta1_deg > (state.total_angle-0.00005) && state.isPolarizationParallel){}
                        else{
                            MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift+state.s2,y1, 
                                            x1+(double)(radiusH/2)-xshift+state.s2,y1,state.s4,colorino);
                            MaestroG.drawLineThick(g, x1-xshift+state.s2, y1-(double)(radiusH/2), 
                                            x1-xshift+state.s2, y1+(double)(radiusH/2), state.s4,colorino);
                        }
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, 
                                    x1+2*radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, state.s4,colorino);
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, 
                                    x1+2*radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, state.s4,colorino);
                        }
                    }
                    else{
                        // make a plus sign
                        if(state.theta1_deg < (state.total_angle+0.00005) && state.theta1_deg > (state.total_angle-0.00005) && state.isPolarizationParallel){}
                        else{
                            MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift+state.s2,y1, 
                                            x1+(double)(radiusH/2)-xshift+state.s2, y1,state.s4,colorino);
                            MaestroG.drawLineThick(g, x1-xshift+state.s2, y1-(double)(radiusH/2), 
                                            x1-xshift+state.s2, y1+(double)(radiusH/2), state.s4,colorino);
                        }
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, 
                                    x1+2*radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, state.s4,colorino);
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, 
                                    x1+2*radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, state.s4,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, y1+radiusnewy+vettoreL, vettoreL, colorE, thicknessV);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs2("E","i","//","x","",g,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 + 2*radiusnewy ));                        
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                     (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,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 5*radiusnewy/8 ));
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                    (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, y1+radiusnewy+vettoreL, vettoreL, colorE, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs2("E","i","//","x","",g,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 + 2*radiusnewy ));
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,
                                                    (int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                    (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,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 5*radiusnewy/8 ));
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                    (int)(y1 + 3.0*(radiusnewy)));
                        }
                    }
                }

            if(show_normal){    
                //An oval for magnetic field                
                if(Field_Out){
                        MaestroG.fillCircleThick(g, x1-radiusnewx, y1+(radiusnewy), (double)radiusH, state.s2, Color.white);
                        MaestroG.fillCircleThick(g, x1-radiusnewx, y1+radiusnewy, (double)state.s5,state.s2,colorH);
                        MaestroG.drawCircleThick(g, x1-radiusnewx, y1+radiusnewy, (double)radiusH,state.s4,colorH);
                        g.setColor(Color.blue);  
                        // INCIDENT 
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        MaestroG.subscriptersupBs2("H","i","//","y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                     (int)(y1 + radiusnewy));
                }
                else{
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1+(radiusnewy), (double)radiusH, state.s2, Color.white);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2),
                                    y1+(radiusnewy)-(double)(radiusH/2),
                                    x1-(radiusnewx) + (double)(radiusH/2),
                                    y1+(radiusnewy) + (double)(radiusH/2), state.s4,colorH);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2),
                                    y1+(radiusnewy)-(double)(radiusH/2),
                                    x1-(radiusnewx) - (double)(radiusH/2),
                                    y1+(radiusnewy) + (double)(radiusH/2), state.s4,colorH);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx),
                                    y1+(radiusnewy), (double)radiusH,state.s4,colorH);
                
                        g.setColor(Color.blue);                   
                        // INCIDENT 
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        MaestroG.subscriptersupBs2("H","i","//","y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                     (int)(y1 + radiusnewy));        
               }
            }
        }
	else{ // Perpendicular Polarization - Incident Wave
                double yshift = (double)state.s5;
                double xshift2 = (double)state.s5;
                Color colorino;
                if(show_normal){
                    colorino = colorE;
                }
                else{
                    colorino = colorH;
                }
                
                if(show_normal){
                    // make a plus sign
                    MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift+state.s2,y1, 
                                    x1+(double)(radiusH/2)-xshift+state.s2,y1, state.s4,colorino);
                    MaestroG.drawLineThick(g, x1-xshift + state.s2, y1+(double)(radiusH/2), 
                                    x1-xshift + state.s2, y1-(double)(radiusH/2), state.s4,colorino);
                    // make an equal sign
                    if(state.theta1_deg < (90.0-0.000005)){
                        MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, 
                                    x1+2*radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, state.s4,colorino);
                        MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, 
                                    x1+2*radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, state.s4,colorino);
                    }
                }
                else{
                    if(show_tang){
                        // make a plus sign
                        
                        MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift+state.s2,y1, 
                                    x1+(double)(radiusH/2)-xshift+state.s2,y1, state.s4,colorino);
                        MaestroG.drawLineThick(g, x1-xshift+state.s2, y1+(double)(radiusH/2), 
                                    x1-xshift+state.s2, y1-(double)(radiusH/2), state.s4,colorino);
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, 
                                    x1+2*radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, state.s4,colorino);
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, 
                                    x1+2*radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, state.s4,colorino);
                        }
                    }
                    else{
                        // make a plus sign
                        MaestroG.drawLineThick(g, x1-(double)(radiusH/2)-xshift+state.s2,y1, 
                                    x1+(double)(radiusH/2)-xshift+state.s2,y1, state.s4,colorino);
                        MaestroG.drawLineThick(g, x1-xshift+state.s2, y1+(double)(radiusH/2), 
                                    x1-xshift+state.s2, y1-(double)(radiusH/2), state.s4,colorino);
                        // make an equal sign
                        if(state.theta1_deg < (90.0-0.000005)){
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, 
                                    x1+2*radiusH+xshift2, y1-(double)(radiusH/2)+state.s2, state.s4,colorino);
                            MaestroG.drawLineThick(g, x1+radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, 
                                    x1+2*radiusH+xshift2, y1+(double)(radiusH/2)-state.s2, state.s4,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){
                            ArrowDOWN(g, x1-radiusnewx, y1+radiusnewy+vettoreL, vettoreL, colorH, thicknessV);//*
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBs("H","i","\u22a5x","",g,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 + 2*radiusnewy ));
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        }
                        else{     
                            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,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 5*radiusnewy/8));
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                     (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){
                            ArrowUP(g, x1-radiusnewx, y1+radiusnewy+vettoreL, vettoreL, colorH, thicknessV);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBs("H","i","\u22a5x","",g,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 + 2*radiusnewy));
                            MaestroG.subscripter("Incident Wave","","",g,state.s14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                         (int)(y1 + 3.0*(radiusnewy)));
                        }
                        else{
                            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,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 + 5*radiusnewy/8));
                            MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                         (int)(y1 + 3.0*(radiusnewy)));
                        }
                    }
                }
                //An oval for electric field
                if(Field_Out){
                    if(show_normal){
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1+(radiusnewy), (double)radiusH, state.s4, Color.white);
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1+(radiusnewy), (double)state.s5, state.s2,colorE);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx), y1+(radiusnewy), (double)radiusH, state.s4,colorE);
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(colorE);                   
                        // INCIDENT 
                        MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        MaestroG.subscriptersupBs("E","i","\u22a5y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                     (int)(y1 + radiusnewy));
                    }
                }
                else{
                    if(show_normal){
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1+(radiusnewy), (double)radiusH, state.s4, Color.white);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2),
                                    y1+(radiusnewy)-(double)(radiusH/2), 
                                    x1-(radiusnewx) + (double)(radiusH/2),
                                    y1+(radiusnewy) + (double)(radiusH/2), state.s4,colorE);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2),
                                    y1+(radiusnewy)-(double)(radiusH/2),
                                    x1-(radiusnewx) - (double)(radiusH/2),
                                    y1+(radiusnewy) + (double)(radiusH/2), state.s4,colorE);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx),
                                    y1+(radiusnewy), (double)radiusH, state.s4,colorE);
                        g.setColor(colorE);
                        // INCIDENT 
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        MaestroG.subscripter("Incident Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx))-state.s85, 
                                                     (int)(y1 + 3.0*(radiusnewy)));
                        MaestroG.subscriptersupBs("E","i","\u22a5y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                     (int)(y1 + radiusnewy));
                    }  
                }
        }
    }
    //-------------------------------------------------------------------------------------------
    
    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 = (double)state.s15;
        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 = (double)state.s15;
        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 = (double)state.s15;
        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 = (double)state.s15;            
        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 = getSize().height/2-TopMargin-6*VGap - state.s20;
        radius_powernew = radius*40/100;
        double radius_powernew2;
        radius_powernew2 = radius_powernew + state.s13;
        
	g.setColor(incident);
	double Len = (double)state.s15;
        double LenT = (double)state.s15;
        double LenR = ((double)state.s15) * Math.pow(Math.sin(state.Reflection_Coef.Magnitude()*Math.PI/2.0),0.5);
        
        if(state.Transmission_Coef.Magnitude()>1.0){
            LenT = (double)state.s15;
        }
        else{
            LenT = ((double)state.s15) * Math.pow(Math.sin(state.Transmission_Coef.Magnitude()*Math.PI/2.0),0.5);
        }
        double LenTH = (double)state.s15;
        if(state.Transmission_CoefH.Magnitude()>1.0){
            LenTH = (double)state.s15;
        }
        else{
            LenTH = ((double)state.s15) * 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 = state.s4;
        radiusH = state.s16;
        
        // Find Direction of normal field for the Reflected Component
        if(state.isPolarizationParallel){// Parallel Polarization
            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(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 = state.s50;// these two lines position normal field near interface
        int radiusnewy = state.s50;
        x1 = (double)(getSize().width/2 + state.s2);
        y1 = (double)(getSize().height/2 - state.s1);
        x2 = (double)(getSize().width/2 +(int)(radius_powernew*Math.sin(state.theta1)) + state.s2);
        y2 = (double)(getSize().height/2-(int)(radius_powernew*Math.cos(state.theta1)) - state.s1);
        x2R = (double)(getSize().width/2 +(int)((radius+state.s10)*Math.sin(state.theta1)) + state.s2);
        y2R = (double)(getSize().height/2-(int)((radius+state.s10)*Math.cos(state.theta1)) - state.s1);
          
        double vscaled;
        vscaled = state.beta_ratio*((radius + (double)state.s10) - 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)(getSize().width/2);
            y1 = (double)(getSize().height/2 - state.s1);
            x2 = (double)(getSize().width/2 +(int)(radius_powernew*Math.sin(state.theta2)));
            y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2)) - state.s1);
            x2T = x1+((radius_powernew2+vscaled)*Math.sin(state.theta2));
            y2T = y1+((radius_powernew2+vscaled)*Math.cos(state.theta2));
        }
        else{
            angoloT2 = (Math.PI)+23.0*Math.PI/180.0;
            angoloT = (Math.PI)-23.0*Math.PI/180.0;
            x1 = (double)(getSize().width/2);
            y1 = (double)(getSize().height/2 - state.s1);
            x2 = (double)(getSize().width/2 +(int)(radius_powernew*Math.sin(Math.PI*0.5)));
            y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(Math.PI*0.5)) - state.s1);
            x2T = (double)(getSize().width/2 +(int)((radius+state.s10)*Math.sin(Math.PI*0.5)));
            y2T = (double)(getSize().height/2+(int)((radius+state.s10)*Math.cos(Math.PI*0.5)) - state.s1);
            x2R = (double)(getSize().width/2 +(int)((radius+state.s10)*Math.sin(state.theta1)) + state.s2);
            y2R = (double)(getSize().height/2-(int)((radius+state.s10)*Math.cos(state.theta1)) - state.s1);
            //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)(getSize().width/2 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2)) - state.s1);
                        x2T = (double)(getSize().width/2 +(int)((radius+state.s10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+state.s10)*Math.cos(state.theta2)) - state.s1);
                        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,state.font16,
                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 ) + state.s10);
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBss2("\u03b5","2","E","t","//","z","",g,state.font16,
                                        (int)(x1 + 2*vettoreL/3) + state.s10,(int)(y1 - radiusnewy/2));
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            if(show_tang){
                                if(state.Reflection_Coef.Real() > 0.0){
                                    ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, thicknessV);//*
                                }
                                else{
                                    ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, thicknessV);//*
                                }
                            }
                            else{
                                if(state.Reflection_Coef.Real() > 0.0){
                                    ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorE, thicknessV);
                                }
                                else{
                                    ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorE, thicknessV);
                                }
                            }
                        }
                        else{
                            //An oval for magnetic field
                            MaestroG.fillCircleThick(g, x1+radiusnewx+state.s20, y1, (double)radiusH, state.s2, Color.white);
                            MaestroG.fillCircleThick(g, x1+radiusnewx+state.s20, y1, (double)state.s5,state.s2,colorH);
                            MaestroG.drawCircleThick(g, x1+radiusnewx+state.s20, y1, (double)radiusH, state.s4,colorH);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(Color.blue);                   
                            // Transmission
                            FontMetrics fm; int xspace;
                            g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx), 
                                    (int)(y1 - 3.0*(radiusnewy)));
                            MaestroG.subscriptersupBs2("H","t","//","y","",g,state.font16,(int)(x1 + 3*radiusnewx/2), 
                                    (int)(y1 - radiusnewy));
                        }
                    }
                    else{
                        x2 = (double)(getSize().width/2 + (int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2 + (int)(radius_powernew*Math.cos(state.theta2))-state.s1);
                        x2T = (double)(getSize().width/2 + (int)((radius+state.s10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2 + (int)((radius+state.s10)*Math.cos(state.theta2))-state.s1);
                        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,state.font16,
                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 ) + state.s10);
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                                    (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorE);                   
                                MaestroG.subscriptersupBss2("\u03b5","2","E","t","//","z","",g,state.font16,
                                                    (int)(x1 + 2*vettoreL/3)+10,(int)(y1 - radiusnewy/2));
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                                    (int)(y1 - 3.0*(radiusnewy)));
                            }
                            if(show_tang){
                                if(state.Reflection_Coef.Real() > 0.0){
                                    ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, thicknessV);//*
                                }
                                else{
                                    ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorE, thicknessV);//*
                                }
                            }
                            else{
                                if(state.Reflection_Coef.Real() > 0.0){
                                    ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorE, thicknessV);//*
                                }
                                else{
                                    ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorE, thicknessV);//*
                                }
                            }
                        }
                        else{
                            //An oval for magnetic field
                            MaestroG.fillCircleThick(g, x1+radiusnewx + state.s20, y1, (double)radiusH, state.s2, Color.white);
                            MaestroG.drawLineThick(g, x1+radiusnewx-(double)(radiusH/2) + state.s20,
                                        y1-(double)(radiusH/2),
                                        x1+radiusnewx+ (double)(radiusH/2) + state.s20,
                                        y1 + (double)(radiusH/2), state.s4,colorH);
                            MaestroG.drawLineThick(g, x1+radiusnewx+(double)(radiusH/2) + state.s20,
                                        y1-(double)(radiusH/2),
                                        x1+radiusnewx- (double)(radiusH/2) + state.s20,
                                        y1 + (double)(radiusH/2), state.s4,colorH);
                            MaestroG.drawCircleThick(g, x1+radiusnewx + state.s20, y1, (double)radiusH, state.s4,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,state.font14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                        (int)(y1 - 3.0*(radiusnewy)));
                            MaestroG.subscriptersupBs2("H","t","//","y","",g,state.font16,(int)(x1 + 3*radiusnewx/2), 
                                                     (int)(y1 - radiusnewy));
                        }
                    }
                }
            }
                
            // REFLECTED WAVE

            double y1shiftup = y1 - (double)state.s10;
            double y1shiftup2 = y1 - radiusH - (double)state.s5;
            radiusnewx = state.s50;// these two lines position normal field near interface
            radiusnewy = state.s50;
            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));
                    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,state.font16,
                                                (int)(x1 - vettoreL),(int)(y1 - 2*radiusnewy ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                (int)(y1 - 3.0*(radiusnewy)));
                        }
                        else{
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBss2("\u03b5","1","E","r","//","z","",g,state.font16,
                                                (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                (int)(y1 - 3.0*(radiusnewy)));
                        }
                        if(show_tang){
                            if(state.Reflection_Coef.Real() > 0.0){
                                ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, thicknessV);//*
                            }
                            else{
                                ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, thicknessV);//*
                            }
                        }
                        else{
                            if(state.Reflection_Coef.Real() > 0.0){
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, thicknessV);
                            }
                            else{
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, thicknessV);
                            }
                        }
                    }
                    else{
                        //An oval for magnetic field
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1-radiusnewy, (double)radiusH, state.s2, Color.white);
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1-radiusnewy, (double)state.s5,state.s2,colorH);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx), y1-radiusnewy, (double)radiusH,state.s4,colorH);
                        g.setColor(Color.blue);                   
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        // FIVE ACCA
                        MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));
                        MaestroG.subscriptersupBs2("H","r","//","y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                             (int)((0.96 * y1) - (radiusnewy)));
                    }
                }
                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,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 - 2*radiusnewy ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                 (int)(y1 - 3.0*(radiusnewy)));
                        }
                        else{
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBss2("\u03b5","1","E","r","//","z","",g,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                 (int)(y1 - 3.0*(radiusnewy)));
                        }
                        if(show_tang){
                            if(state.Reflection_Coef.Real() > 0.0){
                                ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, thicknessV);//*
                            }
                            else{
                                ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorE, thicknessV);//*
                            }
                        }
                        else{
                            if(state.Reflection_Coef.Real() < 0.0){
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, thicknessV);//*
                            }
                            else{
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorE, thicknessV);//*
                            }

                        }
                    }
                    else{
                        //An oval for magnetic field
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1-radiusnewy, (double)radiusH, state.s2, Color.white);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2),
                                        y1-radiusnewy-(double)(radiusH/2),
                                        x1-(radiusnewx) + (double)(radiusH/2),
                                        y1-radiusnewy + (double)(radiusH/2), state.s4,colorH);
                         MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2),
                                        y1-radiusnewy-(double)(radiusH/2),
                                        x1-(radiusnewx) - (double)(radiusH/2),
                                        y1-radiusnewy + (double)(radiusH/2), state.s4,colorH);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx), y1-radiusnewy, (double)radiusH,state.s4,colorH);
                        g.setColor(colorH);                   

                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        // SIX ACCA
                        MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                        MaestroG.subscriptersupBs2("H","r","//","y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                             (int)((0.96 * y1) - (radiusnewy)));
                    }
                }
            }
        }
	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)(getSize().width/2 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-state.s1);
                        x2T = (double)(getSize().width/2 +(int)((radius+state.s10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+state.s10)*Math.cos(state.theta2))-state.s1);

                        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,state.font16,
                                                    (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 ) + state.s10);
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                                    (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBss("\u03bc","2","H","t","\u22a5z","",g,state.font16,
                                                    (int)(x1 + 2*vettoreL/3)+state.s10,(int)(y1 - radiusnewy/2 ));
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                                    (int)(y1 - 3.0*(radiusnewy)));
                            }
                            if(show_tang){
                                    ArrowDOWN(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorH, thicknessV); //*
                            }
                            else{
                                    ArrowRIGHT(g, x1+radiusnewx, y1, vettoreL, colorH, thicknessV);//*
                            }
                        }
                        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,state.font14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx), 
                                                         (int)(y1 - 3.0*(radiusnewy)));
                            MaestroG.fillCircleThick(g, x1+radiusnewx+state.s20, y1, (double)radiusH, state.s2, Color.white);

                            MaestroG.fillCircleThick(g, x1+radiusnewx+state.s20, y1, (double)state.s5,state.s2,colorE);
                            MaestroG.drawCircleThick(g, x1+radiusnewx+state.s20, y1, (double)radiusH,state.s4,colorE);
                            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs("E","t","\u22a5y","",g,state.font16,(int)(x1 + 3*radiusnewx/2),(int)(y1 - radiusnewy));
                        }
                    }
                    else{
                        x2 = (double)(getSize().width/2 +(int)(radius_powernew*Math.sin(state.theta2)));
                        y2 = (double)(getSize().height/2+(int)(radius_powernew*Math.cos(state.theta2))-state.s1);
                        x2T = (double)(getSize().width/2 +(int)((radius+state.s10)*Math.sin(state.theta2)));
                        y2T = (double)(getSize().height/2+(int)((radius+state.s10)*Math.cos(state.theta2))-state.s1);
                        // 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,state.font16,
                                                        (int)(x1 + 2*vettoreL/3),(int)(y1 - radiusnewy/2 )+state.s10);
                                FontMetrics fm; int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 +radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            else{
                                g.setColor(colorH);                   
                                MaestroG.subscriptersupBss("\u03bc","2","H","t","\u22a5z","",g,state.font16,
                                                        (int)(x1 + 2*vettoreL/3)+state.s10,(int)(y1 - radiusnewy/2 ));
                                FontMetrics fm;
                                int xspace;
                                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
                                fm = g.getFontMetrics();
                                xspace = fm.stringWidth("Transmitted Wave");
                                MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx),
                                                        (int)(y1 - 3.0*(radiusnewy)));
                            }
                            if(show_tang){
                                    ArrowUP(g, x1+radiusnewx, y1+vettoreL*0.5, vettoreL, colorH, thicknessV);//*
                            }
                            else{
                                    ArrowLEFT(g, x1+radiusnewx, y1, vettoreL, colorH, thicknessV);//*
                            }
                        }
                        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,state.font14));
                            fm = g.getFontMetrics();
                            xspace = fm.stringWidth("Transmitted Wave");
                            MaestroG.subscripter("Transmitted Wave","","",g,state.font14,(int)(x1 + radiusnewx), 
                                                         (int)(y1 - 3.0*(radiusnewy)));
                             MaestroG.fillCircleThick(g, x1+radiusnewx+state.s20, y1, (double)radiusH, state.s2, Color.white);
                             MaestroG.drawLineThick(g, x1+radiusnewx-(double)(radiusH/2)+state.s20,
                                            y1-(double)(radiusH/2),
                                            x1+radiusnewx+(double)(radiusH/2)+state.s20,
                                            y1 + (double)(radiusH/2), state.s4,colorE);
                             MaestroG.drawLineThick(g, x1+radiusnewx+(double)(radiusH/2)+state.s20,
                                            y1-(double)(radiusH/2),
                                            x1+radiusnewx-(double)(radiusH/2)+state.s20,
                                            y1 + (double)(radiusH/2), state.s4,colorE);
                             MaestroG.drawCircleThick(g, x1+radiusnewx+state.s20, y1,(double)radiusH,state.s4,colorE);
                             g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                            g.setColor(colorE);                   
                            MaestroG.subscriptersupBs("E","t","\u22a5y","",g,state.font16,(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,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 - 2*radiusnewy ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, (int)(y1 - 3.0*(radiusnewy)));
                        }
                        else{
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBss("\u03bc","1","H","r","\u22a5z","",g,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8 ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                 (int)(y1 - 3.0*(radiusnewy)));
                        }
                        if(show_tang){
                            if(state.Reflection_CoefH.Real() > 0.0){
                                ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                            else{
                                ArrowUP(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                        }
                        else{    
                            if(state.Reflection_CoefH.Real() < 0.0){
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                            else{
                                ArrowRIGHT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                        }
                    }
                    else{
                        //An oval for electric field
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1-(radiusnewy), (double)radiusH, state.s2, Color.white);
                        MaestroG.fillCircleThick(g, x1-(radiusnewx), y1-(radiusnewy), (double)state.s5, state.s2,colorE);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx), y1-(radiusnewy), (double)radiusH, state.s4,colorE);
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(colorE);                   
                        MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                (int)(y1 - 3.0*(radiusnewy)));
                        MaestroG.subscriptersupBs("E","r","\u22a5y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                (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,state.font16,
                                                    (int)(x1 - vettoreL),(int)(y1 - 2*radiusnewy ));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                 (int)(y1 - 3.0*(radiusnewy)));
                        }
                        else{
                            g.setColor(colorH);                   
                            MaestroG.subscriptersupBss("\u03bc","1","H","r","\u22a5z","",g,state.font16,
                                                    (int)(x1 - 5*vettoreL/4),(int)(y1 - 12*radiusnewy/8));
                            MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                 (int)(y1 - 3.0*(radiusnewy)));
                        }
                        if(show_tang){
                             
                            if(state.Reflection_CoefH.Real() > 0.0){
                                ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                            else{
                                ArrowDOWN(g, x1-radiusnewx, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                        }
                        else{
                            
                            if(state.Reflection_CoefH.Real() < 0.0){
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }
                            else{
                                ArrowLEFT(g, x1-radiusnewx-vettoreL, y1-radiusnewy, vettoreL, colorH, thicknessV);//*
                            }   
                        }
                    }
                    else{
                        //An oval for electric field
                        MaestroG.fillCircleThick(g, x1-(radiusnewx),
                                            y1-(radiusnewy),
                                            (double)radiusH, state.s2, Color.white);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)-(double)(radiusH/2),
                                        y1-(radiusnewy)-(double)(radiusH/2),
                                        x1-(radiusnewx) + (double)(radiusH/2),
                                        y1-(radiusnewy) + (double)(radiusH/2), state.s4,colorE);
                        MaestroG.drawLineThick(g, x1-(radiusnewx)+(double)(radiusH/2),
                                        y1-(radiusnewy)-(double)(radiusH/2),
                                        x1-(radiusnewx) - (double)(radiusH/2),
                                        y1-(radiusnewy) + (double)(radiusH/2), state.s4,colorE);
                        MaestroG.drawCircleThick(g, x1-(radiusnewx), y1-(radiusnewy), (double)radiusH,state.s4,colorE);
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                        g.setColor(colorE);                   
                        MaestroG.subscripter("Reflected Wave","","",g,state.font14,(int)((0.9 * x1) - (radiusnewx)) - state.s85, 
                                                         (int)(y1 - 3.0*(radiusnewy)));

                        MaestroG.subscriptersupBs("E","r","\u22a5y","",g,state.font16,(int)(x1 - 5*radiusnewx/2), 
                                                             (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){}
}
