//ObliqueInputPanel.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;

public class ObliqueInputPanel extends Panel implements ChangeListener, ActionListener, ItemListener{
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Color bgcolor = new Color(170,240,240);
    private Font labfont0=new Font("SanSerif",Font.PLAIN,11);
    private Font labfont=new Font("SanSerif",Font.PLAIN,12);
    private Font labfontS=new Font("Serif",Font.PLAIN,13);
    private Font labfontbig=new Font("SanSerif",Font.PLAIN,14);
    private Font labfontbigI=new Font("Serif",Font.ITALIC,14);
    private Font titlefont=new Font("SanSerif",Font.BOLD,12);
    
    private static Font labfontSI = new Font("Serif",Font.ITALIC,14);
    private static Font labfontB = new Font("SanSerif",Font.BOLD,17);
    private static Font labfontB2 = new Font("SanSerif",Font.BOLD,12);
    
    private static final int SCROLLMIN = 0;
    private static final int SCROLLMAX = 9001;
    Label titlelabel;	
    Label lab1, lab2, lab3, lab3b, lab4, lab5, lab6, lab7, lab8, lab9, lab10,
          labm1, labm2, labpa, labpb, labpc, labpd, labpe, labpf, 
          labr1, labr2, labr3, labr4, labHz, labSm,
          labeqa, labeqb, labeqc, labeqd, labeqe, labeqf, labclick;
    public Label labplot;
    Label vlab1;
    TextField text1, text2, text3, text4, text5, text6, text7;
    Button b1;
    //  Buttons instead on radio buttons (which do not scale easily)    
    public Button button1, button2, button3, button4, button5, button6, button7, button8, button9;
    public Panel pbut1, pbut2, pbut3, pbut4, pbut5, pbut6, pbut7, pbut8, pbut9;
    
    public Label labscale, labscale1, labscale2;
    public Panel scale1, scale2;
    
    public Checkbox c1, c2, c3, c4, c5, c6, c7, c8, c9;
    public CheckboxGroup cgrp, cgrp2, cgrp3, cgfield;
    public JSlider slider, slider2, slider_scale;
    private Oblique_State state;
    public TitleCanvas title;
    
    public ObliqueInputPanel(Oblique_State state){
	super();
	this.state = state;
        int shiftup = state.s14;
        labfont0=new Font("SanSerif",Font.PLAIN,state.font11);
        labfont=new Font("SanSerif",Font.PLAIN,state.font12);
        labfontS=new Font("Serif",Font.PLAIN,state.font13);
        labfontbig=new Font("SanSerif",Font.PLAIN,state.font14);
        labfontbigI=new Font("Serif",Font.ITALIC,state.font14);
        titlefont=new Font("SanSerif",Font.BOLD,state.font12);
	
        labfontSI = new Font("Serif",Font.ITALIC,state.font13);
        labfontB2 = new Font("SanSerif",Font.BOLD,state.font12);
        labfontB = new Font("SanSerif",Font.BOLD,state.font14);
        
        setBackground(bgcolor);
	setLayout(null);
	titlelabel = new Label("Input",Label.LEFT);
	titlelabel.setFont(new Font("SanSerif",Font.BOLD,state.font16));
	titlelabel.setBounds(state.s5,state.s3,state.s45,state.s17);
        titlelabel.setForeground(Color.red.darker());
	//title = new TitleCanvas();
	//add(title);
	//title.setBounds(state.s1,state.s1,state.s75,state.s25);
	
	labclick = new Label("Click Update",Label.RIGHT);
	labclick.setFont(titlefont);
	labclick.setForeground(Color.red);
        labclick.setVisible(false);
            
	labm1 = new Label("Medium 1",Label.RIGHT);
	labm1.setFont(labfont);
	labm1.setForeground(Color.red.darker());
        
        labm2 = new Label("Medium 2",Label.RIGHT);
	labm2.setFont(labfont);
	labm2.setForeground(Color.blue.darker());
        
	lab1 = new Label("\u03b5",Label.RIGHT);
	lab1.setFont(labfontbig);
	
	lab2 = new Label("\u03bc",Label.RIGHT);
	lab2.setFont(labfontbig);
        
        labr1 = new Label("r",Label.LEFT);
	labr1.setFont(labfont);
        labr2 = new Label("r",Label.LEFT);
	labr2.setFont(labfont);
        labr3 = new Label("r",Label.LEFT);
	labr3.setFont(labfont);
        labr4 = new Label("r",Label.LEFT);
	labr4.setFont(labfont);
        
        labeqa = new Label("=",Label.RIGHT);
	labeqa.setFont(labfontbig);
	labeqb = new Label("=",Label.RIGHT);
	labeqb.setFont(labfontbig);
        labeqc = new Label("=",Label.RIGHT);
	labeqc.setFont(labfontbig);
        labeqd = new Label("=",Label.RIGHT);
	labeqd.setFont(labfontbig);
	labeqe = new Label("=",Label.RIGHT);
	labeqe.setFont(labfontbig);
        labeqf = new Label("=",Label.RIGHT);
	labeqf.setFont(labfontbig);
        labHz = new Label("Hz",Label.LEFT);
	labHz.setFont(labfontbig);
        
        labSm = new Label("S/m",Label.LEFT);
	labSm.setFont(labfont0);
        
	lab3 = new Label("Incident Transverse Field",Label.LEFT);
	lab3.setFont(labfont);
	
        lab3b = new Label("Component",Label.CENTER);
	lab3b.setFont(labfont);
        
        labpa = new Label("| \u0393 | , | \u03c4 |",Label.CENTER);
	labpa.setFont(labfontS);
        labpb = new Label("|t|",Label.CENTER);
	labpb.setFont(labfont);
        
        labpc = new Label("\u0393 , \u03c4",Label.CENTER);
	labpc.setFont(labfontS);
        labpd = new Label("t",Label.CENTER);
	labpd.setFont(labfont);
        
        labpe = new Label("R , T",Label.CENTER);
	labpe.setFont(labfontS);
        labpf = new Label("T",Label.CENTER);
	labpf.setFont(labfont);
        
        labplot = new Label("PLOT",Label.LEFT);
        labplot.setFont(labfont);
        
	labscale = new Label("plot-zoom",Label.LEFT);
	labscale.setFont(labfont0);
        labscale1 = new Label("plot",Label.LEFT);
	labscale1.setFont(labfont0);
        labscale2 = new Label("zoom",Label.LEFT);
	labscale2.setFont(labfont0);
        
        text1 = new TextField("1.0");// epsilon_r
	text1.setFont(labfont);
	
	text2 = new TextField("1.0");// mu_r
	text2.setFont(labfont);
	
	text3 = new TextField("0.0");// sigma
	text3.setFont(labfont);
	
	lab4 = new Label("\u03b5",Label.RIGHT);
	lab4.setFont(labfontbig);
	
	lab5 = new Label("\u03bc",Label.RIGHT);
	lab5.setFont(labfontbig);
	
	lab6 = new Label("\u03c3",Label.RIGHT);
	lab6.setFont(labfontbig);
	
        lab10 = new Label("FIELD",Label.LEFT);
	lab10.setFont(labfont);
	
        text4 = new TextField("2.55"); // epsilon_r
	text4.setFont(labfont);
	
	text5 = new TextField("1.0"); // mu_r
	text5.setFont(labfont);
	
	text6 = new TextField("1.0"); // sigma
	text6.setFont(labfont);
	
	lab7 = new Label("f ",Label.RIGHT);
	lab7.setFont(labfont);
	
	text7 = new TextField("1.0E9");
	text7.setFont(labfont);
	
	b1 = new Button("UPDATE");
	b1.setFont(labfont);
        
	cgrp = new CheckboxGroup();
	c1 = new Checkbox("//",cgrp,true);
	c1.setFont(labfont);
	c2 = new Checkbox("\u22a5",cgrp,false);
	c2.setFont(labfont);
        
        button2 = new Button("//");
	button2.setFont(labfontB);
	button1 = new Button("\u22a5");
	button1.setFont(labfontB);
		
        cgrp2 = new CheckboxGroup();
        c3 = new Checkbox(" In",cgrp2,true);
	c3.setFont(labfont);
	c4 = new Checkbox("Out",cgrp2,false);
	c4.setFont(labfont);
	
        button3 = new Button("In");
	button3.setFont(labfontB2);
	button4 = new Button("Out");
	button4.setFont(labfontB2);
	
        cgrp3 = new CheckboxGroup();
	c5 = new Checkbox("",cgrp3,true);
	c5.setFont(labfont);
	c6 = new Checkbox("",cgrp3,false);
	c6.setFont(labfont);
	c7 = new Checkbox("",cgrp3,false);
	c7.setFont(labfont);
        
        button5 = new Button("| \u0393 | , | \u03c4 |");
	button5.setFont(labfontSI);
	button6 = new Button("\u0393 ,  \u03c4");
	button6.setFont(labfontSI);
	button7 = new Button("R ,  T");
	button7.setFont(labfontSI);
	
        cgfield = new CheckboxGroup();
	c8 = new Checkbox("Electric",cgfield,true);
	c8.setFont(labfont);
	c9 = new Checkbox("Magnetic",cgfield,false);
	c9.setFont(labfont);
        
        button8 = new Button("Electric");
	button8.setFont(labfontB2);
	button9 = new Button("Magnetic");
	button9.setFont(labfontB2);
        
	lab8 = new Label("Angle of Incidence: ",Label.LEFT);
	lab8.setFont(labfont);
	
	lab9 = new Label("Polarization: ",Label.LEFT);
	lab9.setFont(labfont);

	
	slider = new JSlider(SCROLLMIN,901);
	slider.setValue(450);
	slider2 = new JSlider(SCROLLMIN,1000);
	slider2.setValue(0);
        slider_scale = new JSlider(1,50);
	slider_scale.setValue(5);
	/*
	slider = new Scrollbar(Scrollbar.HORIZONTAL,450,1,SCROLLMIN,901);
	slider2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,1000);
        slider_scale = new Scrollbar(Scrollbar.HORIZONTAL,5,1,1,50);
	*/
        slider.setBackground(bgcolor);
        slider2.setBackground(bgcolor);
        slider_scale.setBackground(bgcolor);
        
	vlab1 = new Label("45 \u00ba",Label.LEFT);
	
	add(titlelabel);
        add(labclick);
	add(labm1);
        add(labm2);
        add(lab1);
	add(text1);
	add(lab2);
	add(text2);
	add(lab3);
        add(lab3b);
        add(labr1); add(labr2); add(labr3); add(labr4);
        add(labeqa); add(labeqb); add(labeqc); add(labeqd); add(labeqe); add(labeqf);
        add(labHz); add(labSm);
        //add(labpa); 
        add(labpb); 
        //add(labpc); 
        add(labpd); 
        //add(labpe); 
        add(labpf);
        add(labplot);
        
	//add(text3);
	add(lab4);
	add(text4);
	add(lab5);
	add(text5);
	add(lab10);
        add(lab6);
	add(text6);
	add(lab7);
	add(text7);
	add(b1);
        
	//add(c1);
	//add(c2);
        //add(c3);
        //add(c4);
        //add(c5);
        //add(c6);
        //add(c7);
        //add(c8);
        //add(c9);
        add(button1);
        add(button2);
        add(button3);
        add(button4);
        add(button5);
        add(button6);
        add(button7);
        add(button8);
        add(button9);
        
	add(lab8);
	add(lab9);
	add(slider);
        add(slider2);
        add(slider_scale);
	add(vlab1);
	
	//lab7.setBounds(10,33,175,20);   
	text7.setBounds(state.s55,state.s59-shiftup,state.s75,state.s19);
	
        //labclick.setBounds(185,5,80,25);
        lab7.setBounds(state.s10,state.s61-shiftup,state.s25,state.s20);
        lab7.setFont(labfontbigI);
        labeqe.setBounds(state.s40,state.s61-shiftup,state.s15,state.s20);
        labHz.setBounds(state.s132,state.s61-shiftup,state.s25,state.s20);
        lab7.setForeground(Color.black);
        labeqe.setForeground(Color.black);
        labHz.setForeground(Color.black);
        
        lab1.setBounds(state.s10,state.s81-shiftup,state.s20,state.s20);
        labr1.setBounds(state.s30,state.s86-shiftup,state.s10,state.s20);
        labeqa.setBounds(state.s40,state.s81-shiftup,state.s15,state.s20);
        lab1.setForeground(Color.red.darker());
        labr1.setForeground(Color.red.darker());
        labeqa.setForeground(Color.red.darker());
        text1.setBounds(state.s55,state.s80-shiftup,state.s75,state.s19);
        
        text1.setForeground(Color.red.darker());
	lab2.setBounds(state.s10,state.s100-shiftup,state.s20,state.s20);
        labr2.setBounds(state.s30,state.s105-shiftup,state.s10,state.s20);
        labeqb.setBounds(state.s40,state.s100-shiftup,state.s15,state.s20);
        lab2.setForeground(Color.red.darker());
        labr2.setForeground(Color.red.darker());
        labeqb.setForeground(Color.red.darker());
        text2.setBounds(state.s55,state.s101-shiftup,state.s75,state.s19);
        text2.setForeground(Color.red.darker());
        
        labm1.setBounds(state.s55,state.s122-shiftup,state.s65,state.s14); //****
        labm2.setBounds(state.s195,state.s122-shiftup,state.s65,state.s14);//****
        
        Panel line1 = new Panel();
	    line1.setBackground(Color.black);
	    add(line1);
	    //line1.setBounds(state.s15,state.s139,state.s200+state.s70,1);
            line1.setBounds(state.s15,state.s123,state.s200+state.s70,1);
        lab4.setBounds(state.s150,state.s79-shiftup,state.s20,state.s20);
        labr3.setBounds(state.s170,state.s84-shiftup,state.s10,state.s20);
        labeqc.setBounds(state.s180,state.s79-shiftup,state.s15,state.s20);
        labSm.setBounds(state.s200+state.s70,state.s61-shiftup,state.s24,state.s20);
        labSm.setForeground(Color.blue.darker());
        
        lab4.setForeground(Color.blue.darker());
        labr3.setForeground(Color.blue.darker());
        labeqc.setForeground(Color.blue.darker());
        text4.setBounds(state.s195,state.s80-shiftup,state.s75,state.s19); //epsilon_r medium 2
	text4.setForeground(Color.blue.darker());
        
        lab5.setBounds(state.s150,state.s100-shiftup,state.s20,state.s20);
        labr4.setBounds(state.s170,state.s105-shiftup,state.s10,state.s20);
        labeqd.setBounds(state.s180,state.s100-shiftup,state.s15,state.s20);
	lab5.setForeground(Color.blue.darker());
        labr4.setForeground(Color.blue.darker());
        labeqd.setForeground(Color.blue.darker());
        text5.setBounds(state.s195,state.s101-shiftup,state.s75,state.s19); // mu_r medium 2
        text5.setForeground(Color.blue.darker());
	//text3.setBounds(195,146,75,20);
	
	labeqf.setBounds(state.s180,state.s58-shiftup,state.s15,state.s20);
        labeqf.setForeground(Color.blue.darker());
        lab6.setBounds(state.s155,state.s58-shiftup,state.s20,state.s20);
        lab6.setForeground(Color.blue.darker());
	text6.setBounds(state.s195,state.s59-shiftup,state.s75,state.s19);
        
        int ypos_block1 = state.s32; 
	b1.setBounds(state.s195,ypos_block1-shiftup,state.s75,state.s20);
        b1.setBackground(new Color(250,250,250));
        
        Panel pb1 = new Panel();
	    pb1.setBackground(Color.cyan);
	    add(pb1);
	    pb1.setBounds(state.s195-1,ypos_block1-1-shiftup,state.s75+2,state.s20+2);
	    
	Panel pb2 = new Panel();
	    pb2.setBackground(Color.black);
	    add(pb2);
	    pb2.setBounds(state.s195-2,ypos_block1-2-shiftup,state.s75+4,state.s20+4);
            
        //---------------------------------------------
	int ypos_block3 = state.s125;
	lab9.setBounds(state.s25,ypos_block3,state.s90,state.s15);
        lab3.setBounds(state.s130,ypos_block3,state.s160,state.s15);
        
        // CHANGE ==============================================================
	//c1.setBounds(70,155,40,20);
	//c2.setBounds(30,155,35,20);
        c1.setBounds(state.s65,state.s152,state.s45,state.s25);
	c2.setBounds(state.s15,state.s152,state.s45,state.s25);
	//======================================================================
	c1.setBackground(bgcolor);
	c2.setBackground(bgcolor);
        
        //button2.setBounds(state.s65,ypos_block3+state.s17,state.s40,state.s20);
	//button1.setBounds(state.s15,ypos_block3+state.s17,state.s40,state.s20);
	//button2.setBackground(Color.red);
	//button1.setBackground(Color.white);
        //button2.setForeground(Color.white);
	//button1.setForeground(Color.black);
        
        button2.setBounds(state.s65,ypos_block3+state.s17,state.s40,state.s20);
	button1.setBounds(state.s15,ypos_block3+state.s17,state.s40,state.s20);
        pbut2 = new Panel();
	    pbut2.setBackground(Color.black);
	    pbut2.setBounds(state.s65-1,ypos_block3+state.s17-1,state.s40+2,state.s20+2);
	pbut1 = new Panel();
	    pbut1.setBackground(Color.black);
	    pbut1.setBounds(state.s15-1,ypos_block3+state.s17-1,state.s40+2,state.s20+2);
	add(pbut2); add(pbut1);
        
	button2.setBackground(Color.white);
	button1.setBackground(Color.white);
        button2.setForeground(Color.red);
	button1.setForeground(Color.gray);
	// CHANGE ==============================================================
        //c3.setBounds(145,155,35,20);
	//c4.setBounds(215,155,45,20);
        //lab3.setBounds(state.s120,state.s140,state.s160,state.s15);
	c3.setBounds(state.s120,state.s152,state.s52,state.s25);
	c4.setBounds(state.s200+state.s15,state.s152,state.s52,state.s25);
        //lab3.setBounds(state.s130,state.s140,state.s160,state.s15);
        //======================================================================
        c3.setBackground(bgcolor);
	c4.setBackground(bgcolor);
        
        //button3.setBounds(state.s125,ypos_block3+state.s17,state.s40,state.s20);
	//button3.setBackground(Color.red);
        //button3.setForeground(Color.white);
	//button4.setBounds(state.s200+state.s5,ypos_block3+state.s17,state.s40,state.s20);
	//button4.setBackground(Color.white);
        //button4.setForeground(Color.black);
        
        button3.setBounds(state.s125,ypos_block3+state.s17,state.s50,state.s20);
	button3.setBackground(Color.white);
        button3.setForeground(Color.red);
	button4.setBounds(state.s200+state.s15,ypos_block3+state.s17,state.s50,state.s20);
	button4.setBackground(Color.white);
        button4.setForeground(Color.gray);
        
        pbut3 = new Panel();
	    pbut3.setBackground(Color.black);
	    pbut3.setBounds(state.s125-1,ypos_block3+state.s17-1,state.s50+2,state.s20+2);
	pbut4 = new Panel();
	    pbut4.setBackground(Color.black);
	    pbut4.setBounds(state.s200+state.s15-1,ypos_block3+state.s17-1,state.s50+2,state.s20+2);
	add(pbut3); add(pbut4);
        
	Panel line2 = new Panel();
	    line2.setBackground(Color.black);
	    add(line2);
	    //line2.setBounds(state.s15,state.s177,state.s200+state.s70,1);
            line2.setBounds(state.s15,state.s169,state.s200+state.s70,1);
        // CHANGE ==============================================================
        //c8.setBounds(110,180,70,20);
	c8.setBounds(state.s65,state.s180,state.s80,state.s18);
        //======================================================================
        c8.setBackground(bgcolor);
        c8.setForeground(Color.magenta.darker());
        // CHANGE ==============================================================
        //c9.setBounds(210,180,75,20);
        c9.setBounds(state.s167,state.s180,state.s85,state.s18);
        //======================================================================
	c9.setBackground(bgcolor);
        c9.setForeground(Color.blue);
        
        //lab10.setBounds(state.s20, state.s182, state.s45, state.s15);
        //c5.setBounds(110,200,60,20);
	//c5.setBackground(bgcolor);
        //c6.setBounds(210,200,60,20);
	//c6.setBackground(bgcolor);
        //c7.setBounds(30,200,60,20);
	//c7.setBackground(bgcolor);
        int ypos_block4 = state.s192;
        
        /*
        button5.setBounds(state.s135,ypos_block4+state.s5,state.s70,state.s20);
	button6.setBounds(state.s200+state.s15,ypos_block4+state.s5,state.s60,state.s20);
	button7.setBounds(state.s65,ypos_block4+state.s5,state.s60,state.s20);
	
        button5.setBackground(Color.white);
        button6.setBackground(Color.white);
        button7.setBackground(Color.white);

        button5.setForeground(Color.red);
        button6.setForeground(Color.black);
        button7.setForeground(Color.black);
        */
        
        button5.setBounds(state.s131,ypos_block4+state.s5,state.s80,state.s20);
	button6.setBounds(state.s200+state.s20,ypos_block4+state.s5,state.s60,state.s20);
	button7.setBounds(state.s60,ypos_block4+state.s5,state.s60,state.s20);
        
        pbut5 = new Panel();
	    pbut5.setBackground(Color.black);
	    pbut5.setBounds(state.s131-1,ypos_block4+state.s5-1,state.s80+2,state.s20+2);
	pbut6 = new Panel();
	    pbut6.setBackground(Color.black);
	    pbut6.setBounds(state.s200+state.s20-1,ypos_block4+state.s5-1,state.s60+2,state.s20+2);
	pbut7 = new Panel();
	    pbut7.setBackground(Color.black);
	    pbut7.setBounds(state.s60-1,ypos_block4+state.s5-1,state.s60+2,state.s20+2);
	add(pbut5); add(pbut6); add(pbut7);
        
        button5.setBackground(Color.white);
        button6.setBackground(Color.white);
        button7.setBackground(Color.white);

        button5.setForeground(Color.red);
        button6.setForeground(Color.gray);
        button7.setForeground(Color.gray);
        
        //c5.setBounds(110,ypos_block4,60,20);
	//c5.setBackground(bgcolor);
        //c6.setBounds(210,ypos_block4,60,20);
	//c6.setBackground(bgcolor);
        //c7.setBounds(15,ypos_block4,60,20);
	//c7.setBackground(bgcolor);
        //labpa.setBounds(160,ypos_block4+3,55,15); 
        //labpc.setBounds(260,ypos_block4+3,30,15); 
        //labpe.setBounds(72,ypos_block4+3,30,15);
        
        c5.setBounds(140,ypos_block4,25,20);
	c5.setBackground(bgcolor);
        c6.setBounds(230,ypos_block4,25,20);
	c6.setBackground(bgcolor);
        c7.setBounds(65,ypos_block4,25,20);
	c7.setBackground(bgcolor);
        //labpa.setBounds(165,ypos_block4+3,55,15); 
        //labpc.setBounds(255,ypos_block4+3,30,15); 
        //labpe.setBounds(90,ypos_block4+3,30,15); 
        //labplot.setBounds(20,ypos_block4+3,45,15);
        labplot.setBounds(state.s15,ypos_block4+state.s7,state.s42,state.s15);
        //======================================================================
        //labpa.setBounds(150,202,50,15); 
        //labpb.setBounds(85,180,20,15);
        
        //labpc.setBounds(250,202,30,15); 
        //labpd.setBounds(175,180,20,15);
        
        //labpe.setBounds(70,202,30,15); 
        //labpf.setBounds(265,180,20,15);
        
        int ypos_block5 = state.s173;
        c8.setBounds(state.s65,ypos_block5,state.s80,state.s25);
	c8.setBackground(bgcolor);
        c8.setForeground(Color.magenta.darker());
        c9.setBounds(state.s167,ypos_block5,state.s85,state.s25);
	c9.setBackground(bgcolor);
        c9.setForeground(Color.blue);
        
        //button8.setBounds(state.s80,ypos_block5,state.s80,state.s20);
	//button8.setBackground(Color.magenta.darker());
        //button8.setForeground(Color.white);
        //button9.setBounds(state.s175,ypos_block5,state.s85,state.s20);
	//button9.setBackground(Color.white);
        //button9.setForeground(Color.black);
        
        button8.setBounds(state.s75,ypos_block5,state.s90,state.s20);
	button8.setBackground(Color.white);
        button8.setForeground(Color.magenta.darker());
        button9.setBounds(state.s175,ypos_block5,state.s90,state.s20);
	button9.setBackground(Color.white);
        button9.setForeground(Color.gray);
        
        pbut8 = new Panel();
	    pbut8.setBackground(Color.black);
	    pbut8.setBounds(state.s75-1,ypos_block5-1,state.s90+2,state.s20+2);
	pbut9 = new Panel();
	    pbut9.setBackground(Color.black);
	    pbut9.setBounds(state.s175-1,ypos_block5-1,state.s90+2,state.s20+2);
	add(pbut8); add(pbut9);
        
        //lab10.setBounds(state.s20, ypos_block5+state.s3, state.s45, state.s15);
        lab10.setBounds(state.s15, ypos_block5+state.s3, state.s45, state.s15);
        
        Panel line3 = new Panel();
	    line3.setBackground(Color.black);
	    add(line3);
	    line3.setBounds(state.s15,state.s200+state.s21,state.s200+state.s70,1);
        
	lab8.setBounds(state.s50,state.s200+state.s23,state.s120,state.s15);
        // CHANGE
	//lab9.setBounds(state.s25,state.s140,state.s90,state.s15);
	
        if(state.IsMac){
            slider.setBounds(state.s20+state.s14,state.s200+state.s44,state.s200+state.s60-state.s28,state.s15);
            slider2.setBounds(state.s20+state.s14,state.s200+state.s64,state.s200+state.s60-state.s28,state.s15);
        }
        else{
            slider.setBounds(state.s20,state.s200+state.s44,state.s200+state.s60,state.s15);
            slider2.setBounds(state.s20,state.s200+state.s64,state.s200+state.s60,state.s15);
        }
        
        slider_scale.setBounds(state.s55,state.s25,state.s75,state.s15);
	/*
	scale2 = new Panel();
	    scale2.setBackground(Color.cyan);
	    add(scale2);
	    scale2.setBounds(state.s55-1,state.s25-1,state.s75+2,state.s15+2);
	scale1 = new Panel();
	    scale1.setBackground(Color.black);
	    add(scale1);
	    scale1.setBounds(state.s55-2,state.s25-2,state.s75+4,state.s15+4);
	add(scale2); add(scale1);  
        scale1.setVisible(false);
        scale2.setVisible(false);
	*/
        labscale.setVisible(false);
        //labscale1.setVisible(false);
        //labscale2.setVisible(false);
        slider_scale.setVisible(false);
        
        labscale.setBounds(state.s68,state.s8,state.s70,state.s15);
        //labscale1.setBounds(state.s15,state.s18,state.s50,state.s15);
        //labscale2.setBounds(state.s13,state.s30,state.s50,state.s15);
        add(labscale);
        //add(labscale1);
        //add(labscale2);
        
        vlab1.setBounds(state.s180,state.s200+state.s23,state.s80,state.s15);
	vlab1.setFont(labfont);
        /*
	Panel pslider2 = new Panel();
	    pslider2.setBackground(Color.cyan);
	    pslider2.setBounds(state.s20-1,state.s200+state.s44-1,state.s200+state.s60+2,state.s15+2);
	    
	Panel pslider1 = new Panel();
	    pslider1.setBackground(Color.black);
	    pslider1.setBounds(state.s20-2,state.s200+state.s44-2,state.s200+state.s60+4,state.s15+4);
        
        Panel pslider4 = new Panel();
	    pslider4.setBackground(Color.gray.cyan);
	    pslider4.setBounds(state.s20-1,state.s200+state.s64-1,state.s200+state.s60+2,state.s15+2);
                              
	Panel pslider3 = new Panel();
	    pslider3.setBackground(Color.black);
	    pslider3.setBounds(state.s20-2,state.s200+state.s64-2,state.s200+state.s60+4,state.s15+4);
        add(pslider4);
        add(pslider3);
        add(pslider2);
        add(pslider1);
	*/
	
	//Listeners 
	slider.addChangeListener(this);	
        slider2.addChangeListener(this);
        slider_scale.addChangeListener(this);
        
        
        b1.addActionListener(this);
        button1.addActionListener(this);
        button2.addActionListener(this);
        button3.addActionListener(this);
        button4.addActionListener(this);
        button5.addActionListener(this);
        button6.addActionListener(this);
        button7.addActionListener(this);
	button8.addActionListener(this);
        button9.addActionListener(this);
	
	c1.addItemListener(this);
	c2.addItemListener(this);
        c3.addItemListener(this);
        c4.addItemListener(this);
   }
   
    public void stateChanged(ChangeEvent evt){
	if(evt.getSource()==slider){
            //labclick.setVisible(true);
	    if(slider.getValue()==900){
		state.theta1 = Math.PI/2;
		vlab1.setText("90.0 \u00ba ");
		slider.setValue(900);
                slider2.setValue(0);
                slider2.setEnabled(false);
                //state.ignition();
            }
	    else{
		//state.theta1 = slider.getValue()*Math.PI/1800.0;
		//vlab1.setText(""+slider.getValue()/10.0+" \u00ba ");
                state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4)),6);
                vlab1.setText(""+(MaestroA.rounder(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4),6))+" \u00ba ");
                slider2.setEnabled(true);
                //slider2.setValue(0);
                //state.ignition();
            }
	}
        if(evt.getSource()==slider2){
                //labclick.setVisible(true);
		state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4)),6);
                vlab1.setText(""+(MaestroA.rounder(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4),6))+" \u00ba ");
                //state.ignition();
	}
	//state.ignition();
    }

    
    public void actionPerformed(ActionEvent evt){
		// CHANGE - ADD THIS CODE ======================================
                if(evt.getSource() == button2){
                    //button2.setBackground(Color.white);
                    //button1.setBackground(Color.white);
                    button2.setForeground(Color.red);
                    button1.setForeground(Color.gray);
                    
                    state.isPolarizationParallel=true;
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button1){
                    //button1.setBackground(Color.white);
                    //button2.setBackground(Color.white);
                    button1.setForeground(Color.red);
                    button2.setForeground(Color.gray);
                    
                    state.isPolarizationParallel=false;
                    state.ignition();
                    state.scan_coefficients();
                }
                if(evt.getSource() == button3){
                    //button3.setBackground(Color.red);
                    //button4.setBackground(Color.white);
                    button3.setForeground(Color.red);
                    button4.setForeground(Color.gray);
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button4){
                    //button4.setBackground(Color.red);
                    //button3.setBackground(Color.white);
                    button4.setForeground(Color.red);
                    button3.setForeground(Color.gray);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                if(evt.getSource() == button5){
                    //button5.setBackground(Color.white);
                    //button6.setBackground(Color.white);
                    //button7.setBackground(Color.white);
                    
                    button5.setForeground(Color.red);
                    button6.setForeground(Color.gray);
                    button7.setForeground(Color.gray);
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button6){
                    //button5.setBackground(Color.white);
                    //button6.setBackground(Color.white);
                    //button7.setBackground(Color.white);
                    
                    button5.setForeground(Color.gray);
                    button6.setForeground(Color.red);
                    button7.setForeground(Color.gray);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button7){
                    //button5.setBackground(Color.white);
                    //button6.setBackground(Color.white);
                    //button7.setBackground(Color.white);
                    
                    button5.setForeground(Color.gray);
                    button6.setForeground(Color.gray);
                    button7.setForeground(Color.red);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                if(evt.getSource() == button8){
                    button8.setBackground(Color.white);
                    button9.setBackground(Color.white);
                    button8.setForeground(Color.magenta.darker());
                    button9.setForeground(Color.gray);
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button9){
                    button8.setBackground(Color.white);
                    button9.setBackground(Color.white);
                    button8.setForeground(Color.gray);
                    button9.setForeground(Color.blue);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                
                if(evt.getSource() == b1){
                  labclick.setVisible(false);
                  if(Double.valueOf(text1.getText()).doubleValue() < 1.0){
                     text1.setText("1.0");
                  }
                  
                  if(Double.valueOf(text2.getText()).doubleValue() < 1.0){
                     text2.setText("1.0");
                  }
                  
                  if(Double.valueOf(text4.getText()).doubleValue() < 1.0){
                     text4.setText("1.0");
                  }
                  
                  if(Double.valueOf(text5.getText()).doubleValue() < 1.0){
                     text5.setText("1.0");
                  }
                  
                  if(Double.valueOf(text6.getText()).doubleValue() < 1.0e-6){
                     text6.setText("1.0e-6");
                  }
                   
                  if(Double.valueOf(text7.getText()).doubleValue() > 1.0e22){
                     text7.setText("1.0e22");
                  }
                  
                  if(Double.valueOf(text7.getText()).doubleValue() < 1.0){
                     text7.setText("1.0");
                  }
                  
		  state.epsilon_r1=Double.valueOf(text1.getText()).doubleValue();
		  state.mu_r1=Double.valueOf(text2.getText()).doubleValue();
		  state.conductivity1=Double.valueOf(text3.getText()).doubleValue();
		  state.epsilon_r2=Double.valueOf(text4.getText()).doubleValue();
		  state.mu_r2=Double.valueOf(text5.getText()).doubleValue();
		  state.conductivity2=Double.valueOf(text6.getText()).doubleValue();
		  state.frequency=Double.valueOf(text7.getText()).doubleValue();
		}
		state.ignition();
		state.scan_coefficients();
    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource() == c1){
	    state.isPolarizationParallel=true;
	    state.ignition();
	    state.scan_coefficients();
	}
	else if(evt.getSource() == c2){
	    state.isPolarizationParallel=false;
	    state.ignition();
	    state.scan_coefficients();
	}
    }
	
    public void paint(Graphics g){
	//g.setColor(Color.black);
	//g.draw3DRect(0,0,getSize().width-1,getSize().height-1,true);
        
        g.setColor(Color.gray);
            //g.drawLine(15,137,getSize().width-15,137);
            //g.drawLine(15,177,getSize().width-15,177);
            //g.drawLine(15,220,getSize().width-15,220);
        
        // CHANGE ==============================================================
        //double radiusH = 6;
        //double xpos = 270;
        //double ypos2 = 165.0;
        //double xpos2 = 190.0;
        //double ypos = 165.0;
        
        double radiusH = state.s6;
        //double xpos = state.s200+state.s75;
        //double ypos2 = (double)state.s165;
        //double xpos2 = (double)state.s180;
        //double ypos = (double)state.s165;
        
        double xpos = state.s200+state.s80;
        double ypos = (double)state.s152;
        double xpos2 = (double)state.s190;
        double ypos2 = (double)state.s152;
        //======================================================================
            Color colore;
            if(state.isPolarizationParallel){colore = Color.blue;}
            else{colore = Color.magenta.darker();}
            
            MaestroG.drawCircleThick(g, xpos, ypos, (double)state.s1, state.s2, colore);
            MaestroG.drawCircleThick(g, xpos, ypos, radiusH, state.s2, colore);
            
            MaestroG.fillCircleThick(g, xpos2, ypos2, radiusH, state.s2, Color.white);
            MaestroG.drawLineThick(g, xpos2-(double)(radiusH/2), ypos2-(double)(radiusH/2),
                                    xpos2 + (double)(radiusH/2), ypos2 + (double)(radiusH/2), state.s1, colore);
            MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), state.s1,colore);
            MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, state.s2, colore);
	    slider.requestFocusInWindow();
	    slider2.requestFocusInWindow();
	    slider_scale.requestFocusInWindow();
    }

}


class TitleCanvas extends Canvas{
	
	private static final Font normalfont = new Font("Sanserif",Font.PLAIN,12);
	private static final Font subfont    = new Font("Sanserif",Font.PLAIN,10);
	private static final Font titlefont  =new Font("Sanserif",Font.BOLD,16);
	
	public TitleCanvas(){
	    super();
	}
	
	public void paint(Graphics g){
	    int x, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2, ratioZ;
	    double temp3, temp4, temp5, test1, test2, test3, factor1;
	    Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            FontMetrics fm;
	    x = 10;
	    y = 20;
	    dx = 80;
	    dxx = 15;
	    g.setFont(titlefont);
            g.setColor(Color.red.darker());
	    g.drawString("Input",20,20);
            
            
	}
    }
