import java.awt.*; 
import java.awt.event.*;
 
public class Oblique extends Frame implements AdjustmentListener, ActionListener, ItemListener, MouseListener, Runnable, WindowListener{
private static final Color bgcolor = new Color(230,230,230);
//About about;
Instructions instructions;
Panel instrFrame;
TitlePanel titlepanel;
ObliqueCanvas o_canvas;
ObliqueCanvasB o_canvasB;
ObliqueGraphCanvas og_canvas; // Magnitude of reflection and transmission coefficients
ObliqueGraphCanvasB og_canvasB; // Amplitude of reflection and transmision coefficients
ObliqueGraphCanvasC og_canvasC; // Power reflection and transmission coefficients (Reflectivity / Transmissivity)
ObliqueGraphCanvasD og_canvasD; // Standing Wave Pattern
Draw2DCanvasB draw2DB; // Draw 2D animations
Palette palette; // palette for 2D 
ObliqueOutputPanel outputpanel;
ObliqueOutputPanelB outputpanelB;
ObliqueInputPanel  inputpanel;
ObliqueControlPanel o_control;
ObliqueControlPanel2 o_control2;
ObliqueBoundaryControlPanel o_control3;
Oblique_State state;

public Panel poutB;

private StartStopClock ssc;
private Thread tron;
private boolean isTronRunning;
private int SleepTime;
// CHANGE 
public int xmove = 10;
public int ymove = 34;

public static void main(String[] args){
        int xxmove = 20;
        int yymove = 45;
        Oblique f = new Oblique();
        f.setSize(1234+xxmove,645+yymove);
        f.setVisible(true);
        f.setLayout(null);
}

public Oblique(){
    setBackground(bgcolor);
    setLayout(null);
    
    // CHANGE ==================================================================
    //int xmove = 10;
    //int ymove = 34;
    //==========================================================================

    titlepanel = new TitlePanel("Module 8.1","Normal Incidence on","Perfect Conductor");
    //add(titlepanel);
    //about = new About();
    instructions = new Instructions();
    state = new Oblique_State();
    o_canvas = new ObliqueCanvas(state);
    o_canvasB = new ObliqueCanvasB(state);
    og_canvas = new ObliqueGraphCanvas(state);
    og_canvasB = new ObliqueGraphCanvasB(state);
    og_canvasC = new ObliqueGraphCanvasC(state);
    og_canvasD = new ObliqueGraphCanvasD(state);
    outputpanel = new ObliqueOutputPanel(state);
    outputpanelB = new ObliqueOutputPanelB(state);
    inputpanel  = new ObliqueInputPanel(state);
    o_control = new ObliqueControlPanel();
    o_control2 = new ObliqueControlPanel2();
    o_control3 = new ObliqueBoundaryControlPanel();
    draw2DB = new Draw2DCanvasB(state);
    
    palette = new Palette(state);
    
    instructions.setBounds(10+xmove,61+ymove,604,574);
    instrFrame = new Panel();
    instrFrame.setBackground(Color.black);
    instrFrame.setBounds(9+xmove,60+ymove,606,576);

    draw2DB.setBounds(9+xmove,60+ymove,606,576);
    palette.setBounds(594+xmove,61+ymove,20,172);
    palette.setVisible(false);
    draw2DB.setVisible(false);
    titlepanel.setBounds(9+xmove,9+ymove,300,46);
    o_canvas.setBounds(9+xmove,60+ymove,606,576);
    o_canvasB.setBounds(9+xmove,60+ymove,606,576);
    og_canvas.setBounds(620+xmove,10+ymove,605,333);
    og_canvasB.setBounds(620+xmove,10+ymove,605,333);
    og_canvasC.setBounds(620+xmove,10+ymove,605,333);
    og_canvasD.setBounds(620+xmove,10+ymove,605,333);
    o_control.setBounds(315+xmove,11+ymove,299,43);
    // CHANGE ==================================================================
    o_control2.setBounds(9+xmove,606+ymove,235,30);
    //==========================================================================
    
    o_control2.setVisible(false);
    outputpanelB.setVisible(false);
    
    //o_control3.setBounds(390,60,225,30);
    o_control3.setBounds(25+xmove,333+ymove,225,30);
    
    o_control3.setVisible(false);
        
    og_canvasD.setVisible(true);
    og_canvas.setVisible(false);
    og_canvasB.setVisible(false);
    og_canvasC.setVisible(false);
    outputpanel.setBounds(925+xmove,348+ymove,300,288);
    outputpanelB.setBounds(20+xmove+10000,545+ymove,375,80);
    inputpanel.setBounds(620+xmove,348+ymove,300,288);
    
        ssc = new StartStopClock();
	//add(ssc);
	ssc.setBounds(615-148+xmove,600+ymove,148,36);
        //ssc.setBounds(16,424,56,190);
        ssc.setVisible(false);
        //about.setVisible(false);
        //instructions.setVisible(false);
        //instrFrame.setVisible(false);
        
    poutB = new Panel(); //Behind small output panel in boundary conditions
	    poutB.setBackground(Color.black);
	    //add(poutB);
	    poutB.setBounds(19+xmove+10000,544+ymove,377,82);
            poutB.setVisible(false);
            
    Panel pcont = new Panel(); //Behind control panel
	    pcont.setBackground(Color.black);
	    //add(pcont);
	    pcont.setBounds(314+xmove,10+ymove,301,45);         
    
    Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //add(p0);
	    p0.setBounds(3+xmove,3+ymove,1228,639);
	    
    Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    p00.setBounds(xmove,ymove,1234,645);
    
            //if(state.this_year > line.magicyear || (state.this_year == line.magicyear && state.this_month > line.magicmonth)){
	    //state.LicenseExpired = true;
            //}
            //else
            //{ 	    
	    //add(about);
            add(instructions);
            add(instrFrame);
            
            add(titlepanel);
            add(ssc);
            add(outputpanelB);
	    add(poutB);
            add(o_canvas);
            add(o_control3);
            add(o_canvasB);
            add(o_control2);
            
            add(palette);
            add(draw2DB);
            add(og_canvasD);
            add(og_canvas);
            add(og_canvasB);
            add(og_canvasC);
            
	    add(outputpanel);
            
	    add(inputpanel);
	    add(o_control);
            add(pcont);
	    add(p0);
	    add(p00); 
            state.LicenseExpired = false;
            //}
        ssc.setStatus(0,360,1);//  Change here the third number to vary animation speed
	isTronRunning = false;
	SleepTime = 0;
	
	
    //Listeners
    //about.bupdate.addActionListener(this);        
    this.addWindowListener(this);
    instructions.bupdate.addActionListener(this);

    ssc.button1.addMouseListener(this);
    ssc.button2.addMouseListener(this);
	
    inputpanel.slider.addAdjustmentListener(this);
    inputpanel.slider2.addAdjustmentListener(this);	
    inputpanel.slider_scale.addAdjustmentListener(this);	
    
    inputpanel.b1.addActionListener(this);
    
    inputpanel.c1.addItemListener(this); // parallel polarization
    inputpanel.c2.addItemListener(this); // perpendicular polarization
    inputpanel.c3.addItemListener(this); // normal field inward
    inputpanel.c4.addItemListener(this); // normal field outward
    //inputpanel.c5.addItemListener(this); // plot power Refl and Transm Coeff
    //inputpanel.c6.addItemListener(this); // plot magnitude of Refl and Transm Coeff for fields
    //inputpanel.c7.addItemListener(this); // plot amplitude of Refl and Transm Coeff for fields
    inputpanel.c8.addItemListener(this); // plot for Electric field
    inputpanel.c9.addItemListener(this); // plot for Magnetic field
    
    o_control.c1.addItemListener(this);
    o_control.c2.addItemListener(this);
    
    o_control.menuA.addItemListener(this);
    o_control.menuB.addItemListener(this);
    
    o_control.c3.addItemListener(this);
    o_control.c4.addItemListener(this);
    o_control.c5.addItemListener(this);
    
    o_control2.c1.addItemListener(this);
    o_control2.c2.addItemListener(this);
    o_control2.c3.addItemListener(this);
    
    o_control3.c1.addItemListener(this);
    o_control3.c2.addItemListener(this);
    o_control3.c3.addItemListener(this);
    
   }

/*
   public void paint(Graphics g){
    
	Font licensefont = new Font("SanSerif",Font.BOLD,18); 	
	g.setColor(Color.white);	 	
	g.fillRect(0,0,945,765); 	
		
	if(state.LicenseExpired){
	    g.setFont(licensefont);
	
	    g.setColor(Color.red);
	    g.drawString("The software license has expired.", 50, 200);
	    g.setColor(Color.black);
	    g.drawString("Obtain updated files from www.amanogawa.com", 50, 230);
	} 
    }
*/

public void paint(Graphics g){
    
    Font licensefont = new Font("SanSerif",Font.BOLD,18); 
    Font fonto = new Font("SanSerif",Font.PLAIN,12);
    Font fontc = new Font("SanSerif",Font.BOLD,16);
    
	Graphics2D g2d = (Graphics2D)g;
        //g.setColor(Color.white);	
	//g.fillRect(0,0,1250,675);  	
	/*	
	if(state.LicenseExpired){
	    g.setFont(licensefont);
	
	    g.setColor(Color.red);
	    g.drawString("The software license has expired.", 50, 200);
	    g.setColor(Color.black);
	    g.drawString("Obtain updated files from www.amanogawa.com", 50, 230);
	} 
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        int annonuovo = 2006;
        int anno = 2006;
        
        if(anno > state.this_year){
            annonuovo = anno;
        }
        else{
            annonuovo = state.this_year;
        }
        //g.setColor(Color.red.darker());
        //g.setFont(fontc);
        //g.drawString("\u00a9",10,652);
        //g.setFont(fonto);
        //g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,650);
        */
}   

    public void mouseClicked(MouseEvent evt){mouseHandler(evt);}
    public void mouseEntered(MouseEvent evt){;}
    public void mouseExited(MouseEvent evt){;}
    public void mousePressed(MouseEvent evt){;}
    public void mouseReleased(MouseEvent evt){;}
    
    
    private synchronized void mouseHandler(MouseEvent evt){
	if(evt.getSource()==ssc.button1){
            if(tron == null){
		start();
	    }
	    else {
		//tron.resume();
	    }
            ssc.IsStop = false;
            ssc.repaint();
	    isTronRunning = true;
	    //polarcanvas.reset();
	    //state.reset(); 
	    //ssc.reset();
	}
	if(evt.getSource()==ssc.button2){
	    isTronRunning = false;
            ssc.IsStop = true;
            ssc.repaint();
	}
    }
    
    public void start(){
	if(tron == null){
	    tron = new Thread(this);
	    tron.start();
	}
    }
	
    public void stop(){
	if(tron != null){
	    //tron.stop();
	    tron = null;
	}
    }
	
    public void run(){
	while(true){
	    try{
		   Thread.sleep(SleepTime);
	    }
	catch(InterruptedException e){e.printStackTrace();}   
	    if(isTronRunning){
		state.increment();
		
		ssc.increment();
		state.ignition();
                draw2DB.repaint();
	    }
	}
    }
	
    public void pause(boolean tmp){
	 if(tmp){
		isTronRunning = false;
		//tron.suspend();
	 }
	 else {
		isTronRunning = true;
		//tron.resume();
	 }
    }
   
    public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
    }
    
    public void windowOpened(WindowEvent evt){}
    
    public void windowIconified(WindowEvent evt){}
    
    public void windowClosed(WindowEvent evt){}
    
    public void windowDeiconified(WindowEvent evt){}
    
    public void windowActivated(WindowEvent evt){}
    
    public void windowDeactivated(WindowEvent evt){}
   
    
    @Override
    public void adjustmentValueChanged(AdjustmentEvent evt){
        if(evt.getSource()==inputpanel.slider || evt.getSource()==inputpanel.slider2){
                if(state.isPolarizationParallel){   
                        if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Magnetic Field - Standing Wave Pattern (Normal to Interface)","| H | / Ho","z-coordinate");
                            og_canvasD.setTitle("", Color.blue.darker(), Color.magenta.darker());
                        }
                }
                else{   if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Electric Field - Standing Wave Pattern (Normal to Interface)","| E | / Eo","z-coordinate"); 
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                }
        }
	if(evt.getSource()==inputpanel.slider_scale){
            state.Deltax = 0.01 * inputpanel.slider_scale.getValue();
            state.ignition();
            draw2DB.repaint();
        }
        
        o_canvas.repaint();
        o_canvasB.repaint();
	og_canvas.setRefPoint(state.theta1*1800/Math.PI);
	og_canvas.repaint();
        og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
	og_canvasB.repaint();
        og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
	og_canvasC.repaint();
        outputpanel.pwocA.repaint();
        outputpanel.pwocB.repaint();
        outputpanel.pwocB2.repaint();
        outputpanel.pwocC.repaint();
        outputpanel.pwocC2.repaint();
        outputpanelB.pwocD.repaint();
        outputpanelB.pwocE.repaint();
        outputpanelB.pwocF.repaint();
        
        state.ignition();
        og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
        og_canvasD.repaint();
    }
    
    public void actionPerformed(ActionEvent evt){
        //if(evt.getSource()==about.bupdate){
        if(evt.getSource()==instructions.bupdate){
                //about.setVisible(false);
                instructions.setVisible(false);
                instrFrame.setVisible(false);
                
                if(state.ShowWhich == 1){
                    o_control.menuA.select(" Vector Diagrams");
                    
                    instructions.setVisible(false);
                    instrFrame.setVisible(false);
                    state.ShowWhich = 1;
		    o_canvas.setVisible(true);
                    o_canvasB.setVisible(false);
                    draw2DB.setVisible(false);
                    palette.setVisible(false);
                    o_control2.setVisible(false);
                    o_control3.setVisible(false);
                    state.Plot2D = false;
                    if(state.IsScalePlot){
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    else{
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    outputpanelB.setVisible(false);
                    poutB.setVisible(false);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove+10000,545+ymove,375,80);
                    poutB.setBounds(19+xmove+10000,544+ymove,377,82);
                    //==========================================================
                    ssc.setVisible(false);
                    
                }
                else if(state.ShowWhich == 2){
                    o_control.menuA.select(" Transverse Field");
                    
                    state.ShowWhich = 2;
                    instructions.setVisible(false);
                    instrFrame.setVisible(false);
                    o_canvas.setVisible(false);
                    o_canvasB.setVisible(false);
                    draw2DB.setVisible(true);
                    palette.setVisible(true);
                    o_control2.setVisible(true);
                    o_control3.setVisible(false);
                    state.Plot2D = true;
                    state.ignition();
                    draw2DB.repaint();
                    inputpanel.labscale.setVisible(true);
                    inputpanel.slider_scale.setVisible(true);
                    inputpanel.scale1.setVisible(true); 
                    inputpanel.scale2.setVisible(true); 
                    outputpanelB.setVisible(false);
                    poutB.setVisible(false);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove+10000,545+ymove,375,80);
                    poutB.setBounds(19+xmove+10000,544+ymove,377,82);
                    //==========================================================
                    // CHANGE 
                    ssc.setBounds(615-148+xmove,600+ymove,148,36);
                    //==========================================================
                    ssc.setVisible(true);
                }
                else if(state.ShowWhich == 3){
                    o_control.menuA.select(" Boundary Conditions");
                    
                    state.ShowWhich = 3;
                    o_canvas.setVisible(false);
                    o_canvasB.setVisible(true);
                    draw2DB.setVisible(false);
                    palette.setVisible(false);
                    o_control2.setVisible(false);
                    o_control3.setVisible(true);
                    state.Plot2D = false;
                    if(state.IsScalePlot){
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    else{
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    outputpanelB.setVisible(true);
                    poutB.setVisible(true);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove,545+ymove,375,80);
                    poutB.setBounds(19+xmove,544+ymove,377,82);
                    //==========================================================
                    
                    // CHANGE ==================================================
                    ssc.setBounds(615-148+xmove+10000,600+ymove,148,36);
                    ssc.setVisible(false);
                    //==========================================================
                    
                    instructions.setVisible(false);
                    instrFrame.setVisible(false);
                }
                
        }
        
	if(evt.getSource() == inputpanel.b1){
	  state.ignition();
          o_canvas.repaint();
          o_canvasB.repaint();
	  outputpanel.pwocA.repaint();
	  outputpanel.pwocB.repaint();
          outputpanel.pwocB2.repaint();
          outputpanel.pwocC.repaint();
          outputpanel.pwocC2.repaint();
          outputpanelB.pwocD.repaint();
          outputpanelB.pwocE.repaint();
          outputpanelB.pwocF.repaint();
          
	  if(o_control.c1.getState()){
                state.plotE = true;
                state.scan_coefficients();
		og_canvas.setNoRange(false);
		og_canvas.plot(state.x_deg,state.refCM_array);
		og_canvas.setRefPoint(state.theta1*1800/Math.PI);
                og_canvasB.setNoRange(false);
		og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
		og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.ref_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
          }
	    else{
		state.plotE = false;
                state.scan_coefficients();
                og_canvas.setNoRange(false);
		og_canvas.plot(state.x_deg,state.transCM_array);
		og_canvas.setRefPoint(state.theta1*1800/Math.PI);
                og_canvasB.setNoRange(false);
		og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
		og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.trans_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
	    }

          og_canvas.repaint();
          og_canvasB.repaint();
          og_canvasC.repaint();
          og_canvasD.repaint();
	}
    }
    
    public void itemStateChanged(ItemEvent evt){
        
            ItemSelectable ie = evt.getItemSelectable();
	    
            if(evt.getSource()== o_control.menuA){
		if(ie.getSelectedObjects()[0]==" Vector Diagrams"){
                    instructions.setVisible(false);
                    instrFrame.setVisible(false);
                    state.ShowWhich = 1;
		    o_canvas.setVisible(true);
                    o_canvasB.setVisible(false);
                    draw2DB.setVisible(false);
                    palette.setVisible(false);
                    o_control2.setVisible(false);
                    o_control3.setVisible(false);
                    state.Plot2D = false;
                    if(state.IsScalePlot){
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    else{
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true);  
                    }
                    outputpanelB.setVisible(false);
                    poutB.setVisible(false);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove+10000,545+ymove,375,80);
                    poutB.setBounds(19+xmove+10000,544+ymove,377,82);
                    //==========================================================
                    
                    // CHANGE ==================================================
                    ssc.setBounds(615-148+xmove+10000,600+ymove,148,36);
                    ssc.setVisible(false);
                    //==========================================================
                    
		}
		
                //else if(ie.getSelectedObjects()[0]==" \u22a5 Field Amplitude"){
                else if(ie.getSelectedObjects()[0]==" Transverse Field"){
		    state.ShowWhich = 2;
                    instructions.setVisible(false);
                    instrFrame.setVisible(false);
                    o_canvas.setVisible(false);
                    o_canvasB.setVisible(false);
                    draw2DB.setVisible(true);
                    palette.setVisible(true);
                    o_control2.setVisible(true);
                    o_control3.setVisible(false);
                    state.Plot2D = true;
                    state.ignition();
                    draw2DB.repaint();
                    inputpanel.labscale.setVisible(true);
                    inputpanel.slider_scale.setVisible(true);
                    inputpanel.scale1.setVisible(true); 
                    inputpanel.scale2.setVisible(true); 
                    outputpanelB.setVisible(false);
                    poutB.setVisible(false);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove+10000,545+ymove,375,80);
                    poutB.setBounds(19+xmove+10000,544+ymove,377,82);
                    //==========================================================
                    
                    // CHANGE ==================================================
                    ssc.setBounds(615-148+xmove,600+ymove,148,36);
                    ssc.setVisible(true);
                    //==========================================================
		}
                
                else if(ie.getSelectedObjects()[0]==" Boundary Conditions"){
		    state.ShowWhich = 3;
                    o_canvas.setVisible(false);
                    o_canvasB.setVisible(true);
                    draw2DB.setVisible(false);
                    palette.setVisible(false);
                    o_control2.setVisible(false);
                    o_control3.setVisible(true);
                    state.Plot2D = false;
                    if(state.IsScalePlot){
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    else{
                        inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    }
                    outputpanelB.setVisible(true);
                    poutB.setVisible(true);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove,545+ymove,375,80);
                    poutB.setBounds(19+xmove,544+ymove,377,82);
                    ssc.setBounds(615-148+xmove+10000,600+ymove,148,36);
                    //==========================================================
                    ssc.setVisible(false);
                    instructions.setVisible(false);
                    instrFrame.setVisible(false);
		}
                
                else if(ie.getSelectedObjects()[0]==" Instructions"){
		    //about.setVisible(true);
                    instructions.setVisible(true);
                    instrFrame.setVisible(true);
                    
                    o_canvas.setVisible(false);
                    o_canvasB.setVisible(false);
                    draw2DB.setVisible(false);
                    palette.setVisible(false);
                    o_control2.setVisible(false);
                    o_control3.setVisible(false);
                    state.Plot2D = false;
                    inputpanel.labscale.setVisible(true);
                        inputpanel.slider_scale.setVisible(true);
                        inputpanel.scale1.setVisible(true); 
                        inputpanel.scale2.setVisible(true); 
                    outputpanelB.setVisible(false);
                    poutB.setVisible(false);
                    // CHANGE ==================================================
                    outputpanelB.setBounds(20+xmove+10000,545+ymove,375,80);
                    poutB.setBounds(19+xmove+10000,544+ymove,377,82);
                    ssc.setBounds(615-148+xmove+10000,600+ymove,148,36);
                    //==========================================================
                    ssc.setVisible(false);
		}
                
	    }
            
            //ItemSelectable ie = evt.getItemSelectable();
            if(evt.getSource()== o_control.menuB){
		if(ie.getSelectedObjects()[0]=="  Reflection"){
                    /*
                    if(inputpanel.c5.getState()){
                        state.which = 3;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    }
                    else if(inputpanel.c6.getState()){
                        state.which = 3;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    }
                    else if(inputpanel.c7.getState()){
                        state.which = 5;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    }
                    */
                    
                    og_canvas.setTitle("Magnetic Field - Reflection Coefficient Magnitude", Color.blue);
                    og_canvas.setYLabel("| \u0393 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Magnetic Field - Reflection Coefficient", Color.blue);
                    og_canvasB.setYLabel("\u0393 ( H )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasC.setTitle("Reflectivity", Color.black);
                    og_canvasC.setYLabel(" R ");
                    og_canvasC.setYRangeMax(1.0);
                    og_canvasC.setYRangeMin(0.0);
                    og_canvasC.plot(state.x_deg,state.ref_array);
                    og_canvasC.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvas.repaint();
                    og_canvasB.repaint();
                    og_canvasC.repaint();

                    og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                    og_canvasD.repaint();
		}
		if(ie.getSelectedObjects()[0]==" Transmission"){
		    /*
                    if(inputpanel.c5.getState()){
                        state.which = 2;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    }
                    else if(inputpanel.c6.getState()){
                        state.which = 2;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    }
                    else if(inputpanel.c7.getState()){
                        state.which = 6;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    }
                    */

                    og_canvas.setTitle("Electric Field - Transmission Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setYLabel("| \u03c4 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Electric Field - Transmission Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel("\u03c4 ( E )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasC.setTitle("Transmissivity", Color.black);
                    og_canvasC.setYLabel(" T ");
                    og_canvasC.setYRangeMax(1.0);
                    og_canvasC.setYRangeMin(0.0);
                    og_canvasC.plot(state.x_deg,state.trans_array);
                    og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                    og_canvas.repaint();
                    og_canvasB.repaint();
                    og_canvasC.repaint();

                    og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                    og_canvasD.repaint();
		}
                
                if(ie.getSelectedObjects()[0]==" \u22a5 Standing Wave"){
		    og_canvasD.setVisible(true);
            
                    //hide input controls for other plots
                    //inputpanel.c5.setVisible(false);
                    //inputpanel.c6.setVisible(false);
                    //inputpanel.c7.setVisible(false);
                    inputpanel.c8.setVisible(false);
                    inputpanel.c9.setVisible(false);
                    inputpanel.lab10.setVisible(false);
                    inputpanel.labpa.setVisible(false);
                    inputpanel.labpb.setVisible(false);
                    inputpanel.labpc.setVisible(false);
                    inputpanel.labpd.setVisible(false);
                    inputpanel.labpe.setVisible(false);
                    inputpanel.labpf.setVisible(false);

                    inputpanel.labscale.setVisible(true);
                    inputpanel.slider_scale.setVisible(true);
                    inputpanel.scale1.setVisible(true); 
                    inputpanel.scale2.setVisible(true);
                    
                state.ignition();
                if(state.isPolarizationParallel){
                    
                        if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Magnetic Field - Standing Wave Pattern (Normal to Interface)","| H | / Ho","z-coordinate");
                            og_canvasD.setTitle("", Color.blue.darker(), Color.magenta.darker());
                        }
                }
                else{   if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Electric Field - Standing Wave Pattern (Normal to Interface)","| E | / Eo","z-coordinate"); 
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                }
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
               
                    og_canvasD.repaint();
		}
                
	    }
    
        //----------------------------------------------------------------------
	if(evt.getSource() == inputpanel.c8){// Electric
            state.plotE = true;
            state.ignition();
            state.scan_coefficients();
            
            if(o_control.c1.getState()){//Reflection Coefficient
                /*
                if(inputpanel.c5.getState()){
                    state.which = 1;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c6.getState()){
                    state.which = 1;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c7.getState()){
                    state.which = 5;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                */
                og_canvas.setTitle("Electric Field - Reflection Coefficient Magnitude", Color.magenta.darker());
		og_canvas.setYLabel("| \u0393 ( E ) |");
		og_canvas.setNoRange(false);
		og_canvas.plot(state.x_deg,state.refCM_array);
		og_canvas.setRefPoint(state.theta1*1800/Math.PI);
		
                og_canvasB.setTitle("Electric Field - Reflection Coefficient", Color.magenta.darker());
		og_canvasB.setYLabel("\u0393 ( E )");
		og_canvasB.setNoRange(false);
		og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
		og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
		
                og_canvasC.setTitle("Reflectivity", Color.black);
		og_canvasC.setYLabel(" R ");
		og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.ref_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
            
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
            else if(o_control.c2.getState()){//Transmission Coefficient
                /*
                if(inputpanel.c5.getState()){
                    state.which = 2;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c6.getState()){
                    state.which = 2;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c7.getState()){
                    state.which = 6;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                */
                og_canvas.setTitle("Electric Field - Transmission Coefficient Magnitude", Color.magenta.darker());
                og_canvas.setYLabel("| \u03c4 ( E ) |");
                og_canvas.setNoRange(false);
                og_canvas.plot(state.x_deg,state.transCM_array);
                og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                og_canvasB.setTitle("Electric Field - Transmission Coefficient", Color.magenta.darker());
                og_canvasB.setYLabel("\u03c4 ( E )");
                og_canvasB.setNoRange(false);
                og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                og_canvasC.setTitle("Transmissivity", Color.black);
                og_canvasC.setYLabel(" T ");
                og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.trans_array);
                og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
            
        }
        //----------------------------------------------------------------------
        if(evt.getSource() == inputpanel.c9){// Magnetic
            state.plotE = false;
            state.ignition();
            state.scan_coefficients();
            
            if(o_control.c1.getState()){//Reflection Coefficient
                /*
                if(inputpanel.c5.getState()){
                    state.which = 3;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c6.getState()){
                    state.which = 3;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c7.getState()){
                    state.which = 5;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                */
                
                og_canvas.setTitle("Magnetic Field - Reflection Coefficient Magnitude", Color.blue);
		og_canvas.setYLabel("| \u0393 ( H ) |");
		og_canvas.setNoRange(false);
		og_canvas.plot(state.x_deg,state.refCM_array);
		og_canvas.setRefPoint(state.theta1*1800/Math.PI);
		
                og_canvasB.setTitle("Magnetic Field - Reflection Coefficient", Color.blue);
		og_canvasB.setYLabel("\u0393 ( H )");
		og_canvasB.setNoRange(false);
		og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
		og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
		
                og_canvasC.setTitle("Reflectivity", Color.black);
		og_canvasC.setYLabel(" R ");
		og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.ref_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
            
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
            else if(o_control.c2.getState()){//Transmission Coefficient
                /*
                if(inputpanel.c5.getState()){
                    state.which = 4;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c6.getState()){
                    state.which = 4;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c7.getState()){
                    state.which = 6;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                */
                og_canvas.setTitle("Magnetic Field - Transmission Coefficient Magnitude", Color.blue);
                og_canvas.setYLabel("| \u03c4 ( H ) |");
                og_canvas.setNoRange(false);
                og_canvas.plot(state.x_deg,state.transCM_array);
                og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                og_canvasB.setTitle("Magnetic Field - Transmission Coefficient", Color.blue);
                og_canvasB.setYLabel("\u03c4 ( H )");
                og_canvasB.setNoRange(false);
                og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                og_canvasC.setTitle("Transmissivity", Color.black);
                og_canvasC.setYLabel(" T ");
                og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.trans_array);
                og_canvasC.setRefPoint(state.theta1*1800/Math.PI);

                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
        }
        //----------------------------------------------------------------------
        if(evt.getSource() == inputpanel.c3){// In
            o_canvas.Field_Out = false;
            o_canvasB.Field_Out = false;
            o_canvas.repaint();
            o_canvasB.repaint();
            state.IsVectorIn = true;
            outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
        }
        //----------------------------------------------------------------------
        if(evt.getSource() == inputpanel.c4){// False
            o_canvas.Field_Out = true;
            o_canvasB.Field_Out = true;
            o_canvas.repaint();
            o_canvasB.repaint();
            state.IsVectorIn = false;
            outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
        }
        //----------------------------------------------------------------------
        if(evt.getSource() == inputpanel.c1){//Parallel Polarization
	    o_canvas.repaint();
            o_canvasB.repaint();
	    outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
            o_control2.setPolarization(true);
            o_control3.setPolarization(true);
            o_control2.repaint();
            
            o_control3.c1.setLabel("H y"); 
            o_control3.c2.setLabel("E x"); 
            o_control3.c3.setLabel("E z"); 
            
	     if(o_control.c1.getState()){//Reflection Coefficient
		if(inputpanel.c8.getState()){
                    state.plotE = true;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Electric Field - Reflection Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setNoRange(false);
                    og_canvas.setYLabel("| \u0393 ( E ) |");
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Electric Field - Reflection Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel("\u0393 ( E )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Magnetic Field - Reflection Coefficient Magnitude", Color.blue);
                    og_canvas.setNoRange(false);
                    og_canvas.setYLabel("| \u0393 ( H ) |");
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Magnetic Field - Reflection Coefficient", Color.blue);
                    og_canvasB.setYLabel("\u0393 ( H )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                og_canvasC.setTitle("Reflectivity", Color.black);
		og_canvasC.setYLabel(" R ");
                og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
		og_canvasC.plot(state.x_deg,state.ref_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
		og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
	    }
	    else{//Transmission Coefficient
                if(inputpanel.c8.getState()){
                    state.plotE = true;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Electric Field - Transmission Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setYLabel("| \u03c4 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Electric Field - Transmission Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel(" \u03c4 ( E ) ");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Magnetic Field - Transmission Coefficient Magnitude", Color.blue);
                    og_canvas.setYLabel("| \u03c4 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Magnetic Field - Transmission Coefficient", Color.blue);
                    og_canvasB.setYLabel(" \u03c4 ( H ) ");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                og_canvasC.setTitle("Transmissivity", Color.black);
		og_canvasC.setYLabel(" T ");
		og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.trans_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                draw2DB.repaint();
                
                if(state.isPolarizationParallel){
                    
                        if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Magnetic Field - Standing Wave Pattern (Normal to Interface)","| H | / Ho","z-coordinate");
                            og_canvasD.setTitle("", Color.blue.darker(), Color.magenta.darker());
                        }
                }
                else{   if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Electric Field - Standing Wave Pattern (Normal to Interface)","| E | / Eo","z-coordinate"); 
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                }
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	}
        //----------------------------------------------------------------------
	if(evt.getSource() == inputpanel.c2){ //Perpendicular Polarization
	    o_canvas.repaint();
            o_canvasB.repaint();
	    outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
            o_control2.setPolarization(false);
            o_control3.setPolarization(false);
            o_control2.repaint();
            
            o_control3.c1.setLabel("E y"); 
            o_control3.c2.setLabel("H x"); 
            o_control3.c3.setLabel("H z"); 
            
	    if(o_control.c1.getState()){//Reflection Coefficient
		if(inputpanel.c8.getState()){
                    state.plotE = true;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Electric Field - Reflection Coefficient Magnitude", Color.magenta.darker());

                    og_canvas.setYLabel("| \u0393 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Electric Field - Reflection Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel("\u0393 ( E )");
                    og_canvas.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Magnetic Field - Reflection Coefficient Magnitude", Color.blue);

                    og_canvas.setYLabel("| \u0393 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Magnetic Field - Reflection Coefficient", Color.blue);
                    og_canvasB.setYLabel("\u0393 ( H )");
                    og_canvas.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                og_canvasC.setTitle("Reflectivity", Color.black);
		og_canvasC.setYLabel(" R ");
		og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.ref_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
		og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	    }
	    else{//Transmission Coefficient
                if(inputpanel.c8.getState()){
                    state.plotE = true;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Electric Field - Transmission Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setYLabel("| \u03c4 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Electric Field - Transmission Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel("\u03c4 ( E )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Magnetic Field - Transmission Coefficient Magnitude", Color.blue);
                    og_canvas.setYLabel("| \u03c4 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    og_canvasB.setTitle("Magnetic Field - Transmission Coefficient", Color.blue);
                    og_canvasB.setYLabel("\u03c4 ( H )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                }
                og_canvasC.setTitle("Transmissivity", Color.black);
		og_canvasC.setYLabel(" T ");
		og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.trans_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
	    og_canvas.repaint();
            og_canvasB.repaint();
            og_canvasC.repaint();
            draw2DB.repaint();
            
                if(state.isPolarizationParallel){
                    
                        if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Magnetic Field - Standing Wave Pattern (Normal to Interface)","| H | / Ho","z-coordinate");
                            og_canvasD.setTitle("", Color.blue.darker(), Color.magenta.darker());
                        }
                }
                else{   if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.red, Color.blue);
                        }
                        else{
                            og_canvasD.setLabels("Electric Field - Standing Wave Pattern (Normal to Interface)","| E | / Eo","z-coordinate"); 
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                }
                
            og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
            og_canvasD.repaint();
            
	}
        //----------------------------------------------------------------------
        /*
        if(evt.getSource() == inputpanel.c5){//plot of magnitude
            
            o_control.c1.setLabel("Plot \u0393"); 
            o_control.c2.setLabel("Plot \u03c4"); 
            
            inputpanel.c8.setVisible(true);
            inputpanel.c9.setVisible(true);
            inputpanel.lab10.setVisible(true);
            
	    o_canvas.repaint();
            o_canvasB.repaint();
	    outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
	     if(o_control.c1.getState()){//Reflection Coefficient
		if(inputpanel.c8.getState()){
                    state.plotE = true;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Electric Field - Reflection Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setYLabel("| \u0393 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    
                        state.which = 1;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                    
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Magnetic Field - Reflection Coefficient Magnitude", Color.blue);
                    og_canvas.setYLabel("| \u0393 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    
                        state.which = 3;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                }
                
                
		og_canvas.setRefPoint(state.theta1*1800/Math.PI);
		og_canvas.setVisible(true);
                og_canvasB.setVisible(false);
                og_canvasC.setVisible(false);
		og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	    }
	    else{//Transmission Coefficient
                if(inputpanel.c8.getState()){
                    state.plotE = true;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Electric Field - Transmission Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setYLabel("| \u03c4 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                    
                        state.which = 2;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    state.ignition();
                    state.scan_coefficients();
                    og_canvas.setTitle("Magnetic Field - Transmission Coefficient Magnitude", Color.blue);
                    og_canvas.setYLabel("| \u03c4 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.transCM_array);
                        
                        state.which = 4;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                }
                
		og_canvas.setRefPoint(state.theta1*1800/Math.PI);
                og_canvas.setVisible(true);
                og_canvasB.setVisible(false);
                og_canvasC.setVisible(false);
		og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	    }
	    //og_canvas.repaint();
                
	}
        //----------------------------------------------------------------------
        if(evt.getSource() == inputpanel.c6){//Plot of amplitude
	    
            o_control.c1.setLabel("Plot \u0393"); 
            o_control.c2.setLabel("Plot \u03c4"); 
            
            inputpanel.c8.setVisible(true);
            inputpanel.c9.setVisible(true);
            inputpanel.lab10.setVisible(true);
            
            o_canvas.repaint();
            o_canvasB.repaint();
	    outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
	     if(o_control.c1.getState()){//Reflection Coefficient
                 if(inputpanel.c8.getState()){
                     state.plotE = true;
                     
                     state.ignition();
                     state.scan_coefficients();
                    og_canvasB.setTitle("Electric Field - Reflection Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel(" \u0393 ( E ) ");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    
                        state.which = 1;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                 }
                 else if(inputpanel.c9.getState()){
                     state.plotE = false;
                     
                     state.ignition();
                     state.scan_coefficients();
                     og_canvasB.setTitle("Magnetic Field - Reflection Coefficient", Color.blue);
                    og_canvasB.setYLabel(" \u0393 ( H ) ");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                        
                        state.which = 3;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                 }
                 
		og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
		og_canvas.setVisible(false);
                og_canvasB.setVisible(true);
                og_canvasC.setVisible(false);
		og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	    }
	    else{//Transmission Coefficient
                if(inputpanel.c8.getState()){
                    state.plotE = true;
                    
                    state.ignition();
                    state.scan_coefficients();
                    og_canvasB.setTitle("Electric Field - Transmission Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel("\u03c4 ( E )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    
                        state.which = 2;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    
                    state.ignition();
                    state.scan_coefficients();
                    og_canvasB.setTitle("Magnetic Field - Transmission Coefficient", Color.blue);
                    og_canvasB.setYLabel("\u03c4 ( H )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                    
                        state.which = 4;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                }
                
		og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
                og_canvas.setVisible(false);
                og_canvasB.setVisible(true);
                og_canvasC.setVisible(false);
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                inputpanel.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
            }
	    
                og_canvasB.repaint();
            
	}
        //----------------------------------------------------------------------
        if(evt.getSource() == inputpanel.c7){//Power plots
	    
            o_control.c1.setLabel("Plot R"); 
            o_control.c2.setLabel("Plot T"); 
            
            inputpanel.c8.setVisible(false);
            inputpanel.c9.setVisible(false);
            inputpanel.lab10.setVisible(false);
            
            o_canvas.repaint();
            o_canvasB.repaint();
	    outputpanel.pwocA.repaint();
            outputpanel.pwocB.repaint();
            outputpanel.pwocB2.repaint();
            outputpanel.pwocC.repaint();
            outputpanel.pwocC2.repaint();
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
	     if(o_control.c1.getState()){//Reflection Coefficient
                 
                 state.ignition();
                 
		og_canvasC.setTitle("Reflectivity", Color.black);
		og_canvasC.setYLabel(" R ");
                og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.ref_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
		og_canvas.setVisible(false);
                og_canvasB.setVisible(false);
                og_canvasC.setVisible(true);
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
                
                inputpanel.repaint();
                
                        state.which = 5;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
	    }
	    else{//Transmission Coefficient
                
                state.ignition();
		og_canvasC.setTitle("Transmissivity", Color.black);
		og_canvasC.setYLabel(" T ");
		og_canvasC.setYRangeMax(1.0);
                og_canvasC.setYRangeMin(0.0);
                og_canvasC.plot(state.x_deg,state.trans_array);
		og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                og_canvas.setVisible(false);
                og_canvasB.setVisible(false);
                og_canvasC.setVisible(true);
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
                
                inputpanel.repaint();
                    
                        state.which = 6;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
	    }
	        og_canvasC.repaint();
	}
        */
        //----------------------------------------------------------------------
        if(evt.getSource() == o_control2.c1){//Incident
            state.Incident = true;
            state.Reflected = false;
            state.Total = false;
            state.ignition();
            draw2DB.repaint();
        }
        if(evt.getSource() == o_control2.c2){//Reflected
            state.Incident = false;
            state.Reflected = true;
            state.Total = false;
            state.ignition();
            draw2DB.repaint();
        }
        if(evt.getSource() == o_control2.c3){//Total
            state.Incident = false;
            state.Reflected = false;
            state.Total = true;
            state.ignition();
            draw2DB.repaint();
        }
            
        
        //----------------------------------------------------------------------
        if(evt.getSource() == o_control.c3){//Vectors
            o_canvas.setVisible(true);
            o_canvas.setVisible(false);
            draw2DB.setVisible(false);
            palette.setVisible(false);
            o_control2.setVisible(false);
            state.Plot2D = false;
            inputpanel.labscale.setVisible(true);
            //inputpanel.slider_scale.setVisible(false);
            inputpanel.scale1.setVisible(false); 
            inputpanel.scale2.setVisible(false); 
            
            // CHANGE ==========================================================
            ssc.setBounds(615-148+xmove+10000,600+ymove,148,36);
            //==================================================================
            ssc.setVisible(false);
        }
        if(evt.getSource() == o_control.c4){//Fields Distribution
            o_canvas.setVisible(false);
            o_canvas.setVisible(false);
            draw2DB.setVisible(true);
            palette.setVisible(true);
            o_control2.setVisible(true);
            state.Plot2D = true;
            state.ignition();
            draw2DB.repaint();
            inputpanel.labscale.setVisible(true);
            inputpanel.slider_scale.setVisible(true);
            inputpanel.scale1.setVisible(true); 
            inputpanel.scale2.setVisible(true); 
            
            // CHANGE ==========================================================
            ssc.setBounds(615-148+xmove,600+ymove,148,36);
            //==================================================================
            ssc.setVisible(true);
        }
        if(evt.getSource() == o_control.c5){//Standing Wave
            og_canvasD.setVisible(true);
            
            //hide input controls for other plots
            inputpanel.c5.setVisible(false);
            inputpanel.c6.setVisible(false);
            inputpanel.c7.setVisible(false);
            inputpanel.c8.setVisible(false);
            inputpanel.c9.setVisible(false);
            inputpanel.lab10.setVisible(false);
            inputpanel.labpa.setVisible(false);
            inputpanel.labpb.setVisible(false);
            inputpanel.labpc.setVisible(false);
            inputpanel.labpd.setVisible(false);
            inputpanel.labpe.setVisible(false);
            inputpanel.labpf.setVisible(false);
            
            state.IsScalePlot = true;
            inputpanel.labscale.setVisible(true);
            inputpanel.slider_scale.setVisible(true);
            inputpanel.scale1.setVisible(true); 
            inputpanel.scale2.setVisible(true);
            
                state.ignition();
                if(state.isPolarizationParallel){
                    
                        if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                        else{
                            og_canvasD.setLabels("Magnetic Field - Standing Wave Pattern (Normal to Interface)","| H | / Ho","z-coordinate");
                            og_canvasD.setTitle("", Color.blue.darker(), Color.magenta.darker());
                        }
                }
                else{   if(state.theta1 == 0.0){
                            og_canvasD.setLabels("Standing Wave Pattern","| E | / Eo","z-coordinate");
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                        else{
                            og_canvasD.setLabels("Electric Field - Standing Wave Pattern (Normal to Interface)","| E | / Eo","z-coordinate"); 
                            og_canvasD.setTitle("", Color.magenta.darker(), Color.blue.darker());
                        }
                }
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
               
            og_canvasD.repaint();
        }
        //----------------------------------------------------------------------
	if(evt.getSource() == o_control.c1){//Reflection Coefficient
            
            //show input controls for plots
            state.IsScalePlot = false;
            if(state.Plot2D){
                inputpanel.labscale.setVisible(true);
                inputpanel.slider_scale.setVisible(true);
                inputpanel.scale1.setVisible(true); 
                inputpanel.scale2.setVisible(true); 
            }
            else{
                inputpanel.labscale.setVisible(true);
                inputpanel.slider_scale.setVisible(true);
                inputpanel.scale1.setVisible(true); 
                inputpanel.scale2.setVisible(true); 
            }   
            //inputpanel.c5.setVisible(true);
            //inputpanel.c6.setVisible(true);
            //inputpanel.c7.setVisible(true);
            inputpanel.c8.setVisible(true);
            inputpanel.c9.setVisible(true);
            inputpanel.lab10.setVisible(true);
            inputpanel.labpa.setVisible(true);
            inputpanel.labpb.setVisible(true);
            inputpanel.labpc.setVisible(true);
            inputpanel.labpd.setVisible(true);
            inputpanel.labpe.setVisible(true);
            inputpanel.labpf.setVisible(true);
            if(inputpanel.c7.getState()){
                inputpanel.c8.setVisible(false);
                inputpanel.c9.setVisible(false);
                inputpanel.lab10.setVisible(false);
            }
            
            og_canvasD.setVisible(false);
            if(inputpanel.c8.getState()){
                state.plotE = true;
                
                /*
                if(inputpanel.c5.getState()){
                    state.which = 1;
                                        
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                    
                    og_canvas.setTitle("Electric Field - Reflection Coefficient Magnitude", Color.magenta.darker());
                    og_canvas.setYLabel("| \u0393 ( E ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                }
                if(inputpanel.c6.getState()){
                    state.which = 1;
                                        
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                    
                    og_canvasB.setTitle("Electric Field - Reflection Coefficient", Color.magenta.darker());
                    og_canvasB.setYLabel("\u0393 ( E )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);
		
                }
                else if(inputpanel.c7.getState()){
                    state.which = 5;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                    
                    og_canvasC.setTitle("Reflectivity", Color.black);
                    og_canvasC.setYLabel(" R ");
                    og_canvasC.setYRangeMax(1.0);
                    og_canvasC.setYRangeMin(0.0);
                    og_canvasC.plot(state.x_deg,state.ref_array);
                    og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                
                }
                */
            }
            else if(inputpanel.c9.getState()){
                state.plotE = false;
                
                /*
                if(inputpanel.c5.getState()){
                    state.which = 3;
                                        
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                    
                    og_canvas.setTitle("Magnetic Field - Reflection Coefficient Magnitude", Color.blue);
                    og_canvas.setYLabel("| \u0393 ( H ) |");
                    og_canvas.setNoRange(false);
                    og_canvas.plot(state.x_deg,state.refCM_array);
                    og_canvas.setRefPoint(state.theta1*1800/Math.PI);
                    
                }
                if(inputpanel.c6.getState()){
                    state.which = 3;
                                        
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                    
                    og_canvasB.setTitle("Magnetic Field - Reflection Coefficient", Color.blue);
                    og_canvasB.setYLabel("\u0393 ( H )");
                    og_canvasB.setNoRange(false);
                    og_canvasB.plot(state.x_deg,state.refCR_array,state.refCI_array);
                    og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                }
                else if(inputpanel.c7.getState()){
                    state.which = 5;
                    state.ignition();
                    state.scan_coefficients();
                    outputpanel.pwocA.repaint();
                    outputpanel.pwocB.repaint();
                    outputpanel.pwocB2.repaint();
                    outputpanel.pwocC.repaint();
                    outputpanel.pwocC2.repaint();
                    outputpanelB.pwocD.repaint();
                    outputpanelB.pwocE.repaint();
                    outputpanelB.pwocF.repaint();
                    
                    og_canvasC.setTitle("Reflctivity", Color.black);
                    og_canvasC.setYLabel(" R ");
                    og_canvasC.setYRangeMax(1.0);
                    og_canvasC.setYRangeMin(0.0);
                    og_canvasC.plot(state.x_deg,state.ref_array);
                    og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                }
                */
            }
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	}
	//----------------------------------------------------------------------
        if(evt.getSource() == o_control.c2){//Transmission Coefficient
            state.IsScalePlot = false;
            if(state.Plot2D){
                inputpanel.labscale.setVisible(true);
                inputpanel.slider_scale.setVisible(true);
                inputpanel.scale1.setVisible(true); 
                inputpanel.scale2.setVisible(true); 
            }
            else{
                inputpanel.labscale.setVisible(true);
                inputpanel.slider_scale.setVisible(true);
                inputpanel.scale1.setVisible(true); 
                inputpanel.scale2.setVisible(true); 
            }
            
            //show input controls for plots
            //inputpanel.c5.setVisible(true);
            //inputpanel.c6.setVisible(true);
            //inputpanel.c7.setVisible(true);
            inputpanel.c8.setVisible(true);
            inputpanel.c9.setVisible(true);
            inputpanel.lab10.setVisible(true);
            inputpanel.labpa.setVisible(true);
            inputpanel.labpb.setVisible(true);
            inputpanel.labpc.setVisible(true);
            inputpanel.labpd.setVisible(true);
            inputpanel.labpe.setVisible(true);
            inputpanel.labpf.setVisible(true);
            if(inputpanel.c7.getState()){
                inputpanel.c8.setVisible(false);
                inputpanel.c9.setVisible(false);
                inputpanel.lab10.setVisible(false);
            }   
            
            og_canvasD.setVisible(false);
                if(inputpanel.c8.getState()){
                    state.plotE = true;
                    /*
                    if(inputpanel.c5.getState()){
                        state.which = 2;
                        
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                        
                        og_canvas.setTitle("Electric Field - Transmission Coefficient Magnitude", Color.magenta.darker());
                        og_canvas.setYLabel("| \u03c4 ( E ) |");
                        og_canvas.setNoRange(false);
                        og_canvas.plot(state.x_deg,state.transCM_array);
                        og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    }
                    if(inputpanel.c6.getState()){
                        state.which = 2;
                        
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                        
                        og_canvasB.setTitle("Electric Field - Transmission Coefficient", Color.magenta.darker());
                        og_canvasB.setYLabel("\u03c4 ( E )");
                        og_canvasB.setNoRange(false);
                        og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                        og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                    }
                    else if(inputpanel.c7.getState()){

                        state.which = 6;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                        
                        og_canvasC.setTitle("Transmissivity", Color.black);
                        og_canvasC.setYLabel(" T ");
                        og_canvasC.setYRangeMax(1.0);
                        og_canvasC.setYRangeMin(0.0);
                        og_canvasC.plot(state.x_deg,state.trans_array);
                        og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                    
                    }
                    */
                }
                else if(inputpanel.c9.getState()){
                    state.plotE = false;
                    /*
                    if(inputpanel.c5.getState()){
                        state.which = 4;

                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                        
                        og_canvas.setTitle("Magnetic Field - Transmission Coefficient Magnitude", Color.blue);
                        og_canvas.setYLabel("| \u03c4 ( H ) |");
                        og_canvas.setNoRange(false);
                        og_canvas.plot(state.x_deg,state.transCM_array);
                        og_canvas.setRefPoint(state.theta1*1800/Math.PI);

                    }
                    else if(inputpanel.c6.getState()){
                        state.which = 4;

                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                        
                        og_canvasB.setTitle("Magnetic Field - Transmission Coefficient", Color.blue);
                        og_canvasB.setYLabel("\u03c4 ( H )");
                        og_canvasB.setNoRange(false);
                        og_canvasB.plot(state.x_deg,state.transCR_array,state.transCI_array);
                        og_canvasB.setRefPoint(state.theta1*1800/Math.PI);

                    }
                    else if(inputpanel.c7.getState()){
                        state.which = 6;
                        state.ignition();
                        state.scan_coefficients();
                        outputpanel.pwocA.repaint();
                        outputpanel.pwocB.repaint();
                        outputpanel.pwocB2.repaint();
                        outputpanel.pwocC.repaint();
                        outputpanel.pwocC2.repaint();
                        outputpanelB.pwocD.repaint();
                        outputpanelB.pwocE.repaint();
                        outputpanelB.pwocF.repaint();
                        
                        og_canvasC.setTitle("Transmissivity", Color.black);
                        og_canvasC.setYLabel(" T ");
                        og_canvasC.setYRangeMax(1.0);
                        og_canvasC.setYRangeMin(0.0);
                        og_canvasC.plot(state.x_deg,state.trans_array);
                        og_canvasC.setRefPoint(state.theta1*1800/Math.PI);
                    }
                    */
                }
                og_canvas.repaint();
                og_canvasB.repaint();
                og_canvasC.repaint();
                
                og_canvasD.plot(state.x_swp,state.xarrayTot_M,state.xarrayTot_M2,state.theta1,state.isPolarizationParallel);
                og_canvasD.repaint();
	}
        //-------------------------------------------------Choose display of BC
        if(evt.getSource() == o_control3.c1){// tangential (to interface) perpendicular component in BC           
            o_canvasB.show_normal = true;
            state.show_normal = true;
            outputpanelB.pwocD.setVisible(true);
            outputpanelB.pwocE.setVisible(false);
            outputpanelB.pwocF.setVisible(false);
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
            o_canvasB.repaint();
        }
        else if(evt.getSource() == o_control3.c2){// tangential (to interface) parallel component in BC
            o_canvasB.show_normal = false;
            state.show_normal = false;
            o_canvasB.show_tang = true;
                state.show_tang = true;
            outputpanelB.pwocD.setVisible(false);
            outputpanelB.pwocE.setVisible(true);
            outputpanelB.pwocF.setVisible(false);
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
            o_canvasB.repaint();
        }
        else if(evt.getSource() == o_control3.c3){// normal (to interface) parallel component in BC
            o_canvasB.show_normal = false;
            o_canvasB.show_tang = false;
                state.show_tang = false;
            outputpanelB.pwocD.setVisible(false);
            outputpanelB.pwocE.setVisible(false);
            outputpanelB.pwocF.setVisible(true);
            outputpanelB.pwocD.repaint();
            outputpanelB.pwocE.repaint();
            outputpanelB.pwocF.repaint();
            
            o_canvasB.repaint();
        }
        
    }
}
 
