//import java.applet.*; //CHANGE 1 
import java.awt.*;
import java.awt.event.*;

// CHANGE 2
public class RectWaveGuide extends Frame implements ActionListener, AdjustmentListener, ItemListener, MouseListener, WindowListener{
    //About about;
    Instructions instructions;
    Panel instrFrame;
    TitlePanel titlepanel;
    RectWaveGuideCanvas rwc;
    RectWaveGuideInputPanel inputpanel;
    RectWaveGuide_State state;
    SetRangePanel a_panel, a_to_b_panel, frequency_panel;
    RectWaveGuideControlPanel rwconp;
    RectWaveGuideOutputPanel outputpanel;
    RectWaveGuideSpectrumCanvas spectrum;
    RectWaveModeControlPanel rwmc;
    RectWaveGuideCrossCanvas rwcc;
    RectWaveChooser rwcho;
    
    /**
     * Initializes the applet.  You never need to call this directly; it is
     * called automatically by the system once the applet is created.
     */
    
    // CHANGE 3
    public static void main(String[] args){
        int xmove = 20;
        int ymove = 41;
        RectWaveGuide f = new RectWaveGuide();
        f.setSize(1142+xmove,655+ymove);
        f.setVisible(true);
        //f.setLayout(new FlowLayout());
        f.setLayout(null);
    }   
    
    public RectWaveGuide(){//CHANGE 4
	setLayout(null);
        int xmove = 10;
        int ymove = 34;
	titlepanel = new TitlePanel("Module 8.5","Rectangular Waveguide");
	//add(titlepanel);
	//titlepanel.setBounds(10,10,300,40);
        titlepanel.setBounds(9+xmove,10+ymove,300,40);
	
	state = new RectWaveGuide_State();	
	
	rwc = new RectWaveGuideCanvas();
	//add(rwc);
	//rwc.setBounds(11,56,298,293);
        rwc.setBounds(11+xmove,56+ymove,298,293);
	rwc.setRatio(state.a_to_b_ratio);
	
	inputpanel = new RectWaveGuideInputPanel(state);
	//add(inputpanel);
	//inputpanel.setBounds(11,356,298,218);
        //inputpanel.setBounds(11,356,298,285);
        inputpanel.setBounds(11+xmove,356+ymove,298,285);
        
	outputpanel = new RectWaveGuideOutputPanel(state);
	//add(outputpanel);
	//outputpanel.setBounds(317,12,296,336);
        outputpanel.setBounds(317+xmove,12+ymove,296,336);
	outputpanel.setVisible(true);
	
	frequency_panel = new SetRangePanel("Frequency","[ Hz ]");
	//add(frequency_panel);
	//frequency_panel.setBounds(11,356,298,218);
        // CHANGE ==============================================================
        frequency_panel.setBounds(11+xmove,356+ymove,298,285);
        //======================================================================
        
	frequency_panel.setVisible(false);
	frequency_panel.setMinimum(state.frequency_minimum);
	frequency_panel.setMaximum(state.frequency_maximum);
	frequency_panel.setBackg(new Color(236,236,221));
	
	a_panel = new SetRangePanel("Width  a ","[ m ]");
	//add(a_panel);
	//a_panel.setBounds(11,356,298,218);
        // CHANGE ==============================================================
        a_panel.setBounds(11+xmove,356+ymove,298,285);
        //======================================================================
	a_panel.setVisible(false);
	a_panel.setMinimum(state.a_minimum);
	a_panel.setMaximum(state.a_maximum);
	a_panel.setBackg(new Color(236,236,221));
        
	a_to_b_panel = new SetRangePanel("Width Ratio a / b"," ");
	//add(a_to_b_panel);
	//a_to_b_panel.setBounds(11,356,298,218);
        // CHANGE ==============================================================
        a_to_b_panel.setBounds(11+xmove,356+ymove,298,285);
        //======================================================================
	a_to_b_panel.setVisible(false);
	a_to_b_panel.setMinimum(state.a_to_b_ratio_minimum);
	a_to_b_panel.setMaximum(state.a_to_b_ratio_maximum);
	a_to_b_panel.setBackg(new Color(236,236,221));
        
	rwconp = new RectWaveGuideControlPanel();
	//add(rwconp);
	//rwconp.setBounds(317,12,296,36);
        rwconp.setBounds(317+xmove,12+ymove,296,36);
	
	spectrum = new RectWaveGuideSpectrumCanvas(state);
	//add(spectrum);
	//spectrum.setBounds(315,355,605,220);
        //spectrum.setBounds(315,467,817,175);
        spectrum.setBounds(315+xmove,467+ymove,817,175);
        
	rwmc = new RectWaveModeControlPanel(state);
	//add(rwmc);
	//rwmc.setBounds(621,356,298,105);
        //rwmc.setBounds(316,356,298,105);
        rwmc.setBounds(316+xmove,356+ymove,298,105);
	
	rwcc = new RectWaveGuideCrossCanvas(state);
	//add(rwcc);
	rwcc.setVisible(true);
	//rwcc.setBounds(621,56,298,293);
	//rwcc.setBounds(621,11,510,450);
        rwcc.setBounds(621+xmove,11+ymove,510,450);
	
        rwcho = new RectWaveChooser(state);
        //add(rwcho);
        //rwcho.setBounds(630,323,200,25);
        //rwcho.setBounds(20,565,280,70);
        rwcho.setBounds(20+xmove,565+ymove,280,70);
        
        //about = new About();
	//about.setBounds(9,9,912,567);
	//add(about);
        //about.setVisible(false);
        instructions = new Instructions();
	//instructions.setBounds(11,356,908,218);
        //instructions.setBounds(316,468,815,198);
        //instructions.setBounds(621,11,510,450);
        instructions.setBounds(621+xmove,11+ymove,510,450);
        //instructions.setVisible(false);
        instrFrame = new Panel();
        instrFrame.setBackground(Color.black);
	//instrFrame.setBounds(10,355,910,220);
        //instrFrame.setBounds(315,467,817,200);
        //instrFrame.setBounds(621,11,510,450);
        //instrFrame.setVisible(false);
        
	Panel p1 = new Panel();
	    p1.setBackground(Color.black);
	    //add(p1);
	    //p1.setBounds(10,55,300,295);
            p1.setBounds(10+xmove,55+ymove,300,295);
            
            //Behind output canvas
	Panel p20 = new Panel();
	    p20.setBackground(Color.white);
	    //add(p20);
	    //p20.setBounds(316,11,298,338);
            p20.setBounds(316+xmove,11+ymove,298,338);
            
            // Behind Output Panel
	Panel p2 = new Panel();
	    p2.setBackground(Color.black);
	    //add(p2);
	    //p2.setBounds(315,10,300,340);
            p2.setBounds(315+xmove,10+ymove,300,340);
            
            // Behind Input Panel
	Panel p3 = new Panel();
	    p3.setBackground(Color.black);
	    //add(p3);
	    //p3.setBounds(10,355,300,220);
            //p3.setBounds(10,355,300,287);
            p3.setBounds(10+xmove,355+ymove,300,287);
	  
	Panel p40 = new Panel();
	    p40.setBackground(Color.white);
	    //add(p40);
	    //p40.setBounds(316,11,298,38);
            p40.setBounds(316+xmove,11+ymove,298,38);
    
	Panel p4 = new Panel();
	    p4.setBackground(Color.black);
	    //add(p4);
	    //p4.setBounds(315,10,300,40);
            p4.setBounds(315+xmove,10+ymove,300,40);
	    
	// Behind mode selector
	Panel p5 = new Panel();
	    p5.setBackground(Color.black);
	    //add(p5);
	    //p5.setBounds(620,11,300,78);
            //p5.setBounds(620,11,300,78);
            //p5.setBounds(315,355,300,107);
            p5.setBounds(315+xmove,355+ymove,300,107);
	
        Panel p6 = new Panel();
	    p6.setBackground(Color.black);
	    //add(p6);
	    //p6.setBounds(620,55,300,295);
            //p6.setBounds(620,10,512,452);
            p6.setBounds(620+xmove,10+ymove,512,452);
	 
            // Behind whole Applet
	Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //add(p0);
	    //p0.setBounds(3,3,924,579);
            //p0.setBounds(3,3,1135,645);
	    p0.setBounds(3+xmove,3+ymove,1135,645);
            
	Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    //p00.setBounds(0,0,930,585);
            //p00.setBounds(0,0,1141,651);
            p00.setBounds(xmove,ymove,1141,651);
            //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(rwcho);
            add(rwc);
	    add(inputpanel);
	    add(outputpanel);
	    add(frequency_panel);
	    add(a_panel);
	    add(a_to_b_panel);
	    //add(rwconp);
	    add(spectrum);
	    add(rwmc);
	    add(p5);
            
            add(rwcc);
	    
            add(p1);
	    add(p20);
	    add(p2);
	    //add(p40);
	    add(p3);
            //add(p4);
	    add(p6);
            add(p0);
	    add(p00);
	    state.LicenseExpired = false; 	
            //}

		
	//Listeners
        //about.bupdate.addActionListener(this);
        this.addWindowListener(this);// CHANGE 5
        instructions.bupdate.addActionListener(this);
	rwconp.ch1.addItemListener(this);
	//rwconp.ch2.addItemListener(this);
        inputpanel.b1.addActionListener(this);
	inputpanel.b2.addActionListener(this);
	inputpanel.b5.addActionListener(this);
        
        // CHANGE ==============================================================
        inputpanel.b2a.addActionListener(this);
        inputpanel.b2b.addActionListener(this);
        inputpanel.b3a.addActionListener(this);
        inputpanel.b3b.addActionListener(this);
        inputpanel.b4a.addActionListener(this);
        inputpanel.b4b.addActionListener(this);
        //======================================================================
        
	inputpanel.slider1.addAdjustmentListener(this);
	inputpanel.slider2.addAdjustmentListener(this);
	inputpanel.slider5.addAdjustmentListener(this);
	a_panel.b1.addActionListener(this);
	a_to_b_panel.b1.addActionListener(this);
	frequency_panel.b1.addActionListener(this);
	
	rwmc.b11.addMouseListener(this);
	rwmc.b21.addMouseListener(this);
	rwmc.b31.addMouseListener(this);
	rwmc.b41.addMouseListener(this);
	
	rwmc.b12.addMouseListener(this);
	rwmc.b22.addMouseListener(this);
	rwmc.b32.addMouseListener(this);
	rwmc.b42.addMouseListener(this);
	rwmc.c1.addItemListener(this);
	rwmc.c2.addItemListener(this);
	
        rwcho.c1.addItemListener(this);
        rwcho.c2.addItemListener(this);
        rwcho.c3.addItemListener(this);
        rwcho.c4.addItemListener(this);
        
        rwcho.f1.addItemListener(this);
        rwcho.f2.addItemListener(this);
        rwcho.f3.addItemListener(this);
        
	inputpanel.bupdate.addActionListener(this);
        outputpanel.about.addActionListener(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,626,590);  	
	/*	
	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,582);
        //g.setFont(fonto);
        //g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,580);
        */
    }   

    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){}
    
    
    public void adjustmentValueChanged(AdjustmentEvent evt){
	if(evt.getSource()==inputpanel.slider1){
         
         rwc.setWidth(state.a);
	 
	 if(state.frequency>state.minimum_prop_frequency){
		spectrum.setFmax(state.frequency);
		//spectrum.setFmax(state.frequency_maximum);
	    }
	    else{
		spectrum.setFmax(state.minimum_prop_frequency);
	    }
            
            rwc.setFrequency(state.frequency);
            rwc.repaint();
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
            spectrum.repaint();
            outputpanel.rwocA.repaint();
	}
	else if(evt.getSource()==inputpanel.slider2){
	    if(state.frequency>state.minimum_prop_frequency){
		spectrum.setFmax(state.frequency);
		//spectrum.setFmax(state.frequency_maximum);
	    }
	    else{
		spectrum.setFmax(state.minimum_prop_frequency);
	    }
            
            rwc.setFrequency(state.frequency);
            rwc.repaint();
            spectrum.repaint();  
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
            outputpanel.rwocA.repaint();
	}
	
	else if(evt.getSource()==inputpanel.slider5){
	    
            rwc.setRatio(state.a_to_b_ratio);
	    rwc.repaint();
	    rwcc.setWidth(state.a_to_b_ratio);
            //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    spectrum.repaint();
            outputpanel.rwocA.repaint();
	}
	spectrum.repaint();
    }
    
    public void mouseClicked(MouseEvent evt){/*myEventHandler(evt);*/}
    public void mouseEntered(MouseEvent evt){ }
    public void mouseExited(MouseEvent evt) { }
    //public void mousePressed(MouseEvent evt) {rwcc.repaint();}
    public void mouseReleased(MouseEvent evt) { }
     public void mousePressed(MouseEvent evt) {
	
        if(evt.getSource()==rwmc.c1 || evt.getSource()==rwmc.c2){
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
            state.ignition();
            outputpanel.rwocA.repaint();
        }
         
         
        if(evt.getSource()==rwmc.b11){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
            rwcc.repaint();
	    outputpanel.rwocA.repaint();
	}
	else if(evt.getSource()==rwmc.b21){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
	else if(evt.getSource()==rwmc.b31){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
	else if(evt.getSource()==rwmc.b41){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
	if(evt.getSource()==rwmc.b12){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
	else if(evt.getSource()==rwmc.b22){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
	else if(evt.getSource()==rwmc.b32){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
	else if(evt.getSource()==rwmc.b42){
	    //rwprop.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    outputpanel.rwocA.repaint();
	    
	}
    }
    
    public void actionPerformed(ActionEvent evt){
        
        if(evt.getSource()==outputpanel.about){
            //about.setVisible(true);
            instructions.setVisible(true);
            instrFrame.setVisible(true);
        }
        
        //if(evt.getSource()==about.bupdate){
        if(evt.getSource()==instructions.bupdate){
            //about.setVisible(false);
            instructions.setVisible(false);
            instrFrame.setVisible(false);
        }

        
	if(evt.getSource()==inputpanel.bupdate){
	    rwc.setWidth(state.a);
	    rwc.setRatio(state.a_to_b_ratio);
	    
	    if(state.frequency>state.minimum_prop_frequency){
		spectrum.setFmax(state.frequency);
		//spectrum.setFmax(state.frequency_maximum);
	    }
	    else{
		spectrum.setFmax(state.minimum_prop_frequency);
	    }
	 	    
	    rwc.setFrequency(state.frequency);
	    rwc.setEpsilon(state.epsilon_r);
	    rwc.setMu(state.mu_r);
	    
	    rwc.repaint();
	    spectrum.repaint();
	    rwcc.setWidth(state.a_to_b_ratio);
            //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
            
            outputpanel.rwocA.repaint();
            
	}
        else if(evt.getSource()==inputpanel.b2a || evt.getSource()==inputpanel.b2b){
            rwc.setWidth(state.a);
	 
	 if(state.frequency>state.minimum_prop_frequency){
		spectrum.setFmax(state.frequency);
		//spectrum.setFmax(state.frequency_maximum);
	    }
	    else{
		spectrum.setFmax(state.minimum_prop_frequency);
	    }
            
            rwc.setFrequency(state.frequency);
            rwc.repaint();
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
            spectrum.repaint();
            outputpanel.rwocA.repaint();
        }
        else if(evt.getSource()==inputpanel.b3a || evt.getSource()==inputpanel.b3b){
            rwc.setRatio(state.a_to_b_ratio);
	    rwc.repaint();
	    rwcc.setWidth(state.a_to_b_ratio);
            //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	    spectrum.repaint();
            outputpanel.rwocA.repaint();
        }
        else if(evt.getSource()==inputpanel.b4a || evt.getSource()==inputpanel.b4b){
            if(state.frequency>state.minimum_prop_frequency){
		spectrum.setFmax(state.frequency);
		//spectrum.setFmax(state.frequency_maximum);
	    }
	    else{
		spectrum.setFmax(state.minimum_prop_frequency);
	    }
            
            rwc.setFrequency(state.frequency);
            rwc.repaint();
            spectrum.repaint();  
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
            outputpanel.rwocA.repaint();
        }
        
	else if(evt.getSource()==inputpanel.b1){
	    a_panel.setVisible(true);
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    
	}
	else if(evt.getSource()==inputpanel.b2){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(true);
	}
	else if(evt.getSource()==inputpanel.b5){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(true);
	    frequency_panel.setVisible(false);
	}
	else if(evt.getSource()==a_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    state.a_minimum = a_panel.getMinimum();
	    state.a_maximum = a_panel.getMaximum();
	    if(state.a >= state.a_minimum && state.a <= state.a_maximum){
		inputpanel.slider1.setValue((int)(inputpanel.ScrollMax*(state.a-state.a_minimum)
						    /(state.a_maximum-state.a_minimum)));
	    }
	    else if(state.a < state.a_minimum){
		state.a = state.a_minimum;
		inputpanel.slider1.setValue(0);
		inputpanel.text1.setText(""+state.a);
	    }
	
	    else if(state.a > state.a_maximum){
		state.a = state.a_maximum;
		inputpanel.slider1.setValue(inputpanel.ScrollMax);
		inputpanel.text1.setText(""+state.a);
	    }
	    state.ignition();
	    spectrum.repaint();
	}
	else if(evt.getSource()==frequency_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    state.frequency_minimum = frequency_panel.getMinimum();
	    state.frequency_maximum = frequency_panel.getMaximum();
	    if(state.frequency >= state.frequency_minimum && state.frequency <= state.frequency_maximum){
		inputpanel.slider2.setValue((int)(inputpanel.ScrollMax*(state.frequency-state.frequency_minimum)
						    /(state.frequency_maximum-state.frequency_minimum)));
	    }
	    else if(state.frequency < state.frequency_minimum){
		state.frequency = state.frequency_minimum;
		inputpanel.slider2.setValue(0);
		inputpanel.text4.setText(""+state.frequency);
	    }
	
	    else if(state.frequency > state.frequency_maximum){
		state.frequency = state.frequency_maximum;
		inputpanel.slider2.setValue(inputpanel.ScrollMax);
		inputpanel.text4.setText(""+state.frequency);
	    }
	    state.ignition();
	    spectrum.setFmax(state.frequency);
	    
	    spectrum.repaint();
	}
	else if(evt.getSource()==a_to_b_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    state.a_to_b_ratio_minimum = a_to_b_panel.getMinimum();
	    state.a_to_b_ratio_maximum = a_to_b_panel.getMaximum();
	    
	   if(state.a_to_b_ratio >= state.a_to_b_ratio_minimum && state.a_to_b_ratio <= state.a_to_b_ratio_maximum){
		inputpanel.slider5.setValue((int)(inputpanel.ScrollMax*(state.a_to_b_ratio-state.a_to_b_ratio_minimum)
						    /(state.a_to_b_ratio_maximum-state.a_to_b_ratio_minimum)));
	    }
	    else if(state.a_to_b_ratio < state.a_to_b_ratio_minimum){
		state.a_to_b_ratio = state.a_to_b_ratio_minimum;
		inputpanel.slider5.setValue(0);
		inputpanel.text5.setText(""+state.a_to_b_ratio);
	    }
	
	    else if(state.a_to_b_ratio > state.a_to_b_ratio_maximum){
		state.a_to_b_ratio = state.a_to_b_ratio_maximum;
		inputpanel.slider5.setValue(inputpanel.ScrollMax);
		inputpanel.text5.setText(""+state.a_to_b_ratio);
	    }
	    state.ignition(); 
	    spectrum.repaint();
	    
	}
    }
    
    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	
        if(evt.getSource()==rwcho.f1){
            rwcc.linecolor_ON = false;
            rwcc.lineblack_ON = false;
            rwcc.backcolor_ON = true;
            
            rwcc.repaint();    
        }
        
        if(evt.getSource()==rwcho.f2){
            rwcc.linecolor_ON = true;
            rwcc.lineblack_ON = false;
            rwcc.backcolor_ON = false;
            
            rwcc.repaint();    
        }
        
        if(evt.getSource()==rwcho.f3){
            rwcc.linecolor_ON = false;
            rwcc.lineblack_ON = true;
            rwcc.backcolor_ON = false;
            
            rwcc.repaint();    
        }
        
        if(evt.getSource()==rwcho.c1){
            rwcc.IsX = true;
            rwcc.IsY = false;
            rwcc.IsTot = false;
            rwcc.IsS = false;
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
        }
        else if(evt.getSource()==rwcho.c2){
            rwcc.IsX = false;
            rwcc.IsY = true;
            rwcc.IsTot = false;
            rwcc.IsS = false;
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
        } 
        else if(evt.getSource()==rwcho.c3){
            rwcc.IsX = false;
            rwcc.IsY = false;
            rwcc.IsTot = true;
            rwcc.IsS = false;
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
        }
        else if(evt.getSource()==rwcho.c4){
            rwcc.IsX = false;
            rwcc.IsY = false;
            rwcc.IsTot = false;
            rwcc.IsS = true;
            //rwcc.setDirtyFlag(true);
            rwcc.repaint();
        }
        
        if(evt.getSource()==rwmc.c1){
            //rwcc.setDirtyFlag(true);
            rwcc.IsTE = true;
            rwcc.IsTM = false;
            rwcc.repaint();
            //rwcho.redoitE();
            rwcho.IsTE = true;
            rwcho.repaint();
            state.ignition();
            outputpanel.rwocA.repaint();
        }
         
        if(evt.getSource()==rwmc.c2){
            //rwcc.setDirtyFlag(true);
            rwcc.IsTE = false;
            rwcc.IsTM = true;
            rwcc.repaint();
            rwcc.repaint();
            //rwcho.redoitH();
            rwcho.IsTE = false;
            rwcho.repaint();
            state.ignition();
            outputpanel.rwocA.repaint();
        }
        
        if(evt.getSource()==rwconp.ch1){
		/*
                if(ie.getSelectedObjects()[0]==" Input"){
		    inputpanel.setVisible(true);
		    outputpanel.setVisible(false);
		    //rwcc.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Output"){
		    inputpanel.setVisible(false);
		    outputpanel.setVisible(true);
		     //rwcc.setVisible(false);
		    //outputpanel.rwocA.repaint();
		    //outputpanel.rwocB.repaint();
		}
                */
                if(ie.getSelectedObjects()[0]==" Plot Electric Field"){
                    //inputpanel.setVisible(false);
		    //outputpanel.setVisible(false); 
		    rwcc.setVisible(true);
                    //rwcc.setDirtyFlag(true);
		    rwcc.repaint();  
		}
                else if(ie.getSelectedObjects()[0]==" Plot Magnetic Field"){
                    //inputpanel.setVisible(false);
		    //outputpanel.setVisible(false); 
		    rwcc.setVisible(true);
                    //rwcc.setDirtyFlag(true);
		    rwcc.repaint();  
		}
                else if(ie.getSelectedObjects()[0]==" Plot Power Density"){
                    //inputpanel.setVisible(false);
		    //outputpanel.setVisible(false); 
		    rwcc.setVisible(true);
                    //rwcc.setDirtyFlag(true);
		    rwcc.repaint();  
		}
                else if(ie.getSelectedObjects()[0]==" Instructions"){
                    //inputpanel.setVisible(false);
		    //outputpanel.setVisible(false); 
		    //rwcc.setVisible(true);
                    //rwcc.setDirtyFlag(true);
		    //rwcc.repaint();  
		}
                
	}
	else if(evt.getSource()==rwconp.ch2){
	
		if(ie.getSelectedObjects()[0]=="Cross Section"){
                    inputpanel.setVisible(false);
		    outputpanel.setVisible(false); 
		    rwcc.setVisible(true);
                    //rwcc.setDirtyFlag(true);
		    rwcc.repaint();  
		}	
		
		/*if(ie.getSelectedObjects()[0]=="Wave Vector"){
		
		    
		}
		else if(ie.getSelectedObjects()[0]=="Cross Section"){
		 inputpanel.setVisible(false);
		    outputpanel.setVisible(false); 
		    rwcc.setVisible(true);
		    rwcc.repaint();  
		}	
		else if(ie.getSelectedObjects()[0]=="Propagation"){
		    
		}*/
	}
	
	if(evt.getSource()==rwmc.c1){//TE mode was checked
	    spectrum.setTE(true);
	    spectrum.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	}
	else if(evt.getSource()==rwmc.c2){//TM mode was checked
	    spectrum.setTE(false);
	    spectrum.repaint();
	    //rwcc.setDirtyFlag(true);
	    rwcc.repaint();
	}
	
    }
    /**
     * Called to start the applet.  You never need to call this directly; it
     * is called when the applet's document is visited.
     */
    public void start() {
    }

    /**
     * Called to stop the applet.  This is called when the applet's document is
     * no longer on the screen.  It is guaranteed to be called before destroy()
     * is called.  You never need to call this method directly
     */
    public void stop() {
    }

    /**
     * Cleans up whatever resources are being held.  If the applet is active
     * it is stopped.
     */
    public void destroy() {
    }
}

