//ControlPanel3D.java
import java.awt.*;
import java.awt.event.*;

//public class ControlPanel3D extends Panel implements ActionListener, AdjustmentListener, ItemListener{
public class ControlPanel3D extends Panel implements ActionListener {
    private NewGuide_State state;
    
    private static final Color bgcolor = new Color(236,236,221);
    private static final Color circolor = Color.black;
    private Font labfont, labfont3;
    private Font labfont2, labfont4;
    private Font normalfont;
    public int ScrollMax = 360; 
    public int offset = 20;
    private Label titlelabel;
    private Label lab1, lab2, lab3, lab4, lab5, lab6, lab7;
    private Label ulab1, ulab2, ulab3, ulab4, ulab5, ulab6;
    public TextField text1, text2, text3, text4, text5, text6, text7, text8;
    public Scrollbar slider1, slider2, slider3, slider5;
    public CheckboxGroup chgroup1;
    public Checkbox ch1, ch2, ch3, ch4, ch5, ch6, cg1, cg2, cg3, cg4, cg5, cg6;
    //public Checkbox cplot1, cplot2, cplot3;
    //public CheckboxGroup cplot;
    public boolean show_2D_plots, show_polar_plots, show_data;
    
    public  Button b1, b2, b3, b5;
    public  Button bupdate;
    
    private Image im;
    private Graphics buf;
    
    public Button bSpher1, bSpher2, bSpher3, bSpher4, bSpher5, bSpher6, 
            bCart1, bCart2, bCart3, bCart4, bCart5, bCart6;
    public Button bplot1, bplot2, bplot3;
        public Panel pSpher1 = new Panel();
        public Panel pSpher2 = new Panel();
        public Panel pSpher3 = new Panel();
        public Panel pSpher4 = new Panel();
        public Panel pSpher5 = new Panel();
        public Panel pSpher6 = new Panel();
        
        public Panel pCart1 = new Panel();
        public Panel pCart2 = new Panel();
        public Panel pCart3 = new Panel();
        public Panel pCart4 = new Panel();
        public Panel pCart5 = new Panel();
        public Panel pCart6 = new Panel();
        
        public Panel pPlot1 = new Panel();
        public Panel pPlot2 = new Panel();
        public Panel pPlot3 = new Panel();
        
        public Panel ps1, ps2;
  
    public ControlPanel3D(NewGuide_State state){
	super();
	setLayout(null);
	setBackground(bgcolor);
	this.state = state;
	
        labfont = new Font("SanSerif",Font.PLAIN,state.font12);
        labfont2 = new Font("Serif",Font.PLAIN,state.font12);
        labfont3 = new Font("SanSerif",Font.PLAIN,state.font11);
        labfont4 = new Font("SanSerif",Font.PLAIN,state.font10);
        normalfont = new Font("SanSerif",Font.PLAIN,state.font14);
        offset = state.s20;
    
	titlelabel = new Label("Radiation Plots",Label.CENTER);
	titlelabel.setFont(new Font("SanSerif",Font.BOLD,state.font16));
	add(titlelabel);
	titlelabel.setBounds(state.s10,state.s2,state.s200+state.s80,state.s18);
	titlelabel.setForeground(Color.blue);
	
	//CheckboxGroup chgroup1 = new CheckboxGroup();
	chgroup1 = new CheckboxGroup();
	ch1 = new Checkbox("",true,chgroup1);
        ch2 = new Checkbox("",false,chgroup1);
	ch3 = new Checkbox("",false,chgroup1);
	ch4 = new Checkbox("",false,chgroup1);
	ch5 = new Checkbox("",false,chgroup1);
	ch6 = new Checkbox("",false,chgroup1);
	cg1 = new Checkbox("",false,chgroup1);
        cg2 = new Checkbox("",false,chgroup1);
	cg3 = new Checkbox("",false,chgroup1);
	cg4 = new Checkbox("",false,chgroup1);
        cg5 = new Checkbox("",false,chgroup1);
	cg6 = new Checkbox("",false,chgroup1);
	
	//CheckboxGroup cplot = new CheckboxGroup();
	//cplot1 = new Checkbox("2D plots",true,cplot);
        //cplot2 = new Checkbox("Polar plots",false,cplot);
	//cplot3 = new Checkbox("Data",false,cplot);
	show_2D_plots = true;
	show_polar_plots = false;
	show_data = false;
	
	slider1 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ScrollMax+1);//changes phi
        slider1.setBackground(Color.white);
	slider1.setValue(45);
	add(slider1);
	
	slider1.setBounds(state.s84,state.s165,state.s198,state.s15);
	Panel ps9 = new Panel();
	    ps9.setBackground(Color.cyan);
	    add(ps9);
	    ps9.setBounds(state.s84-1,state.s165-1,state.s198+2,state.s15+2);
	    
	Panel ps10 = new Panel();
	    ps10.setBackground(Color.black);
	    add(ps10);
	    ps10.setBounds(state.s84-2,state.s165-2,state.s198+4,state.s15+4);
	
	ch1.setBackground(bgcolor);
	ch2.setBackground(bgcolor);
	ch3.setBackground(bgcolor);
	ch4.setBackground(bgcolor);
	ch5.setBackground(bgcolor);
	ch6.setBackground(bgcolor);
	
	cg1.setBackground(bgcolor);
	cg2.setBackground(bgcolor);
	cg3.setBackground(bgcolor);
	cg4.setBackground(bgcolor);
	cg5.setBackground(bgcolor);
	cg6.setBackground(bgcolor);
	
	ch1.setFont(labfont2);
	ch2.setFont(labfont2);
	ch3.setFont(labfont2);
	ch4.setFont(labfont2);
	ch5.setFont(labfont2);
	ch6.setFont(labfont2);
	cg1.setFont(labfont2);
	cg2.setFont(labfont2);
	cg3.setFont(labfont2);
	cg4.setFont(labfont2);
	cg5.setFont(labfont2);
	cg6.setFont(labfont2);

	
	add(ch1);
	add(ch2);
	add(ch3);
	add(ch4);
	add(ch5);
	add(ch6);
	add(cg1);
	add(cg2);
	add(cg3);
	add(cg4);
	add(cg5);
	add(cg6);
	

	/* NO!!! USING bplot1 - 3 INSTEAD
             also never setting bounds for these, so causing rogue text
                problems with cheerpj (on browser)
	add(cplot1);
	add(cplot2);
	add(cplot3);
	*/
	
        // CHANGE ==============================================================
	//ch1.setBounds(state.s85,state.s46,state.s22,state.s20);
	//ch2.setBounds(state.s155,state.s46,state.s22,state.s20);
	//ch3.setBounds(state.s200+state.s25,state.s46,state.s22,state.s20);
	//ch4.setBounds(state.s85,state.s66,state.s22,state.s20);
	//ch5.setBounds(state.s155,state.s66,state.s22,state.s20);
	//ch6.setBounds(state.s200+state.s25,state.s66,state.s22,state.s20);
	
	//cg1.setBounds(state.s85,state.s86,state.s22,state.s20);
	//cg2.setBounds(state.s155,state.s86,state.s22,state.s20);
	//cg3.setBounds(state.s200+state.s25,state.s86,state.s22,state.s20);
	//cg4.setBounds(state.s85,state.s106,state.s22,state.s20);
	//cg5.setBounds(state.s155,state.s106,state.s22,state.s20);
	//cg6.setBounds(state.s200+state.s25,state.s106,state.s22,state.s20);
	
	//cplot1.setBounds(state.s25,state.s20,state.s90,state.s20);
	//cplot2.setBounds(state.s120,state.s20,state.s105,state.s20);
	//cplot3.setBounds(state.s200+state.s25,state.s20,state.s65,state.s20);
        //======================================================================
        bplot1 = new Button("  2D Plots ");
        bplot2 = new Button("Polar Plots");
        bplot3 = new Button("   Data    ");
        bplot1.setBounds(state.s10,state.s22,state.s80,state.s15);
	bplot2.setBounds(state.s108,state.s22,state.s80,state.s15);
	bplot3.setBounds(state.s200+state.s5,state.s22,state.s80,state.s15);
        bplot1.setFont(labfont3);
        bplot2.setFont(labfont3);
        bplot3.setFont(labfont3);
        bplot1.setBackground(Color.white);
        bplot2.setBackground(Color.white);
        bplot3.setBackground(Color.white);
        bplot1.setForeground(Color.black);
        bplot2.setForeground(Color.black);
        bplot3.setForeground(Color.black);
        add(bplot1); add(bplot2); add(bplot3);
        
	pPlot1 = new Panel();
	    pPlot1.setBackground(Color.black);
	    add(pPlot1);
	    pPlot1.setBounds(state.s10-2,state.s22-2,state.s80+4,state.s15+4);
	    
	pPlot2 = new Panel();
	    pPlot2.setBackground(bgcolor);
	    add(pPlot2);
	    pPlot2.setBounds(state.s108-2,state.s22-2,state.s80+4,state.s15+4);
	
        pPlot3 = new Panel();
	    pPlot3.setBackground(bgcolor);
	    add(pPlot3);
	    pPlot3.setBounds(state.s200+state.s5-2,state.s22-2,state.s80+4,state.s15+4);
	
        //bSpher1 = new Button(" X ");
        if(state.IsMac){
            bSpher1 = new Button(" \u2714 ");  // CHECK MARK        
        }
        else{
            bSpher1 = new Button(" \u2713 ");  // CHECK MARK
        }
        
        bSpher1.setBackground(Color.white);
        bSpher1.setForeground(Color.red);
        bSpher1.setFont(labfont4);
	add(bSpher1);
	bSpher1.setBounds(state.s85,state.s48,state.s22,state.s14);	
	pSpher1 = new Panel();
	    pSpher1.setBackground(Color.red);
	    add(pSpher1);
	    pSpher1.setBounds(state.s85-1,state.s48-1,state.s22+2,state.s14+2);
        
        bSpher2 = new Button(""); 
        bSpher2.setBackground(Color.white);
        bSpher2.setForeground(Color.gray);
        bSpher2.setFont(labfont4);
	add(bSpher2);
	bSpher2.setBounds(state.s155,state.s48,state.s22,state.s14);	
        pSpher2 = new Panel();
	    pSpher2.setBackground(Color.gray);
	    add(pSpher2);
	    pSpher2.setBounds(state.s155-1,state.s48-1,state.s22+2,state.s14+2);
        
        bSpher3 = new Button(""); 
        bSpher3.setBackground(Color.white);
        bSpher3.setForeground(Color.gray);
        bSpher3.setFont(labfont4);
	add(bSpher3);
	bSpher3.setBounds(state.s200+state.s25,state.s48,state.s22,state.s14);	
	pSpher3 = new Panel();
	    pSpher3.setBackground(Color.gray);
	    add(pSpher3);
	    pSpher3.setBounds(state.s200+state.s25-1,state.s48-1,state.s22+2,state.s14+2);
        
        bSpher4 = new Button(""); 
        bSpher4.setBackground(Color.white);
        bSpher4.setForeground(Color.gray);
        bSpher4.setFont(labfont4);
	add(bSpher4);
	bSpher4.setBounds(state.s85,state.s68,state.s22,state.s14);	
	pSpher4 = new Panel();
	    pSpher4.setBackground(Color.gray);
	    add(pSpher4);
	    pSpher4.setBounds(state.s85-1,state.s68-1,state.s22+2,state.s14+2);
        
        bSpher5 = new Button(""); 
        bSpher5.setBackground(Color.white);
        bSpher5.setForeground(Color.gray);
        bSpher5.setFont(labfont4);
	add(bSpher5);
	bSpher5.setBounds(state.s155,state.s68,state.s22,state.s14);	
        pSpher5 = new Panel();
	    pSpher5.setBackground(Color.gray);
	    add(pSpher5);
	    pSpher5.setBounds(state.s155-1,state.s68-1,state.s22+2,state.s14+2);
        
        bSpher6 = new Button(""); 
        bSpher6.setBackground(Color.white);
        bSpher6.setForeground(Color.gray);
        bSpher6.setFont(labfont4);
	add(bSpher6);
	bSpher6.setBounds(state.s200+state.s25,state.s68,state.s22,state.s14);	
	pSpher6 = new Panel();
	    pSpher6.setBackground(Color.gray);
	    add(pSpher6);
	    pSpher6.setBounds(state.s200+state.s25-1,state.s68-1,state.s22+2,state.s14+2);
            
        //======================================================================
        bCart1 = new Button(""); 
        bCart1.setBackground(Color.white);
        bCart1.setForeground(Color.gray);
        bCart1.setFont(labfont4);
	add(bCart1);
	bCart1.setBounds(state.s85,state.s88,state.s22,state.s14);	
	pCart1 = new Panel();
	    pCart1.setBackground(Color.gray);
	    add(pCart1);
	    pCart1.setBounds(state.s85-1,state.s88-1,state.s22+2,state.s14+2);
        
        bCart2 = new Button(""); 
        bCart2.setBackground(Color.white);
        bCart2.setForeground(Color.gray);
        bCart2.setFont(labfont4);
	add(bCart2);
	bCart2.setBounds(state.s155,state.s88,state.s22,state.s14);	
	pCart2 = new Panel();
	    pCart2.setBackground(Color.gray);
	    add(pCart2);
	    pCart2.setBounds(state.s155-1,state.s88-1,state.s22+2,state.s14+2);
        
        bCart3 = new Button(""); 
        bCart3.setBackground(Color.white);
        bCart3.setForeground(Color.gray);
        bCart3.setFont(labfont4);
	add(bCart3);
	bCart3.setBounds(state.s200+state.s25,state.s88,state.s22,state.s14);	
	pCart3 = new Panel();
	    pCart3.setBackground(Color.gray);
	    add(pCart3);
	    pCart3.setBounds(state.s200+state.s25-1,state.s88-1,state.s22+2,state.s14+2);
        
        bCart4 = new Button(""); 
        bCart4.setBackground(Color.white);
        bCart4.setForeground(Color.gray);
        bCart4.setFont(labfont4);
	add(bCart4);
	bCart4.setBounds(state.s85,state.s108,state.s22,state.s14);	
	pCart4 = new Panel();
	    pCart4.setBackground(Color.gray);
	    add(pCart4);
	    pCart4.setBounds(state.s85-1,state.s108-1,state.s22+2,state.s14+2);
        
        bCart5 = new Button(""); 
        bCart5.setBackground(Color.white);
        bCart5.setForeground(Color.gray);
        bCart5.setFont(labfont4);
	add(bCart5);
	bCart5.setBounds(state.s155,state.s108,state.s22,state.s14);	
	pCart5 = new Panel();
	    pCart5.setBackground(Color.gray);
	    add(pCart5);
	    pCart5.setBounds(state.s155-1,state.s108-1,state.s22+2,state.s14+2);
        
        bCart6 = new Button(""); 
        bCart6.setBackground(Color.white);
        bCart6.setForeground(Color.gray);
        bCart6.setFont(labfont4);
	add(bCart6);
	bCart6.setBounds(state.s200+state.s25,state.s108,state.s22,state.s14);	
	pCart6 = new Panel();
	    pCart6.setBackground(Color.gray);
	    add(pCart6);
	    pCart6.setBounds(state.s200+state.s25-1,state.s108-1,state.s22+2,state.s14+2);

	    /* NOT USED
	Panel pplot1 = new Panel();
	    pplot1.setBackground(bgcolor);
	    //add(pplot1);
	    pplot1.setBounds(8,29,282,22);
	    
	Panel pplot2 = new Panel();
	    pplot2.setBackground(Color.black);
	    //add(pplot2);
	    pplot2.setBounds(7,28,284,24);
	    */
	
	lab1 = new Label("Spherical",Label.LEFT);
	lab2 = new Label("Cartesian",Label.LEFT);
	lab1.setFont(labfont);
	lab2.setFont(labfont);
	lab1.setForeground(Color.black);
	lab2.setForeground(Color.black);
	lab1.setBounds(state.s10,state.s46,state.s100,state.s14); 
	lab2.setBounds(state.s10,state.s86,state.s100,state.s14); 
	
	lab3 = new Label("Distance R = ",Label.RIGHT);
	lab3.setFont(labfont3);
	lab3.setForeground(Color.blue);
	text3 = new TextField(""+state.point_distance,8);
        text3.setFont(labfont);
	ulab3 = new Label(" [  ]",Label.LEFT);
	ulab3.setForeground(Color.blue);
	
	lab3.setBounds(state.s10,state.s139,state.s75,state.s20);
	text3.setBounds(state.s90,state.s139,state.s90,state.s20);
	Panel ptext3 = new Panel();
	    ptext3.setBackground(Color.black);
	    ptext3.setBounds(state.s90-1,state.s139-1,state.s90+2,state.s20+2);
	
        ulab3.setBounds(state.s180,state.s137,state.s30,state.s20);
	
	add(lab1);
	add(lab2);
	add(lab3);	
	add(text3);
	add(ptext3);
	    
	// update
	bupdate = new Button("Update");
        bupdate.setBackground(Color.white);
        bupdate.setFont(labfont3);
	add(bupdate);
	bupdate.setBounds(state.s200+state.s20,state.s139,state.s62,state.s16);	
	Panel pupdate = new Panel();
	    pupdate.setBackground(Color.cyan);
	    add(pupdate);
	    pupdate.setBounds(state.s200+state.s19-1,state.s138-1,state.s64+2,state.s18+2);
	    
	Panel pupdate2 = new Panel();
	    pupdate2.setBackground(Color.black);
	    add(pupdate2);
	    pupdate2.setBounds(state.s200+state.s19-2,state.s138-2,state.s64+4,state.s18+4);
	   	
	//Listeners
	//slider1.addAdjustmentListener(this);
	    /* itemlistener doesn't do anything
	ch1.addItemListener(this);
	ch2.addItemListener(this);
	ch3.addItemListener(this);
	ch4.addItemListener(this);
	ch5.addItemListener(this);
	ch6.addItemListener(this);
	cg1.addItemListener(this);
	cg2.addItemListener(this);
	cg3.addItemListener(this);
	cg4.addItemListener(this);
	cg5.addItemListener(this);
	cg6.addItemListener(this);
	cplot1.addItemListener(this);
	cplot2.addItemListener(this);
	    */
	bupdate.addActionListener(this);
        bSpher1.addActionListener(this);
        bSpher2.addActionListener(this);
        bSpher3.addActionListener(this);
        bSpher4.addActionListener(this);
        bSpher5.addActionListener(this);
        bSpher6.addActionListener(this);
        bCart1.addActionListener(this);
        bCart2.addActionListener(this);
        bCart3.addActionListener(this);
        bCart4.addActionListener(this);
        bCart5.addActionListener(this);
        bCart6.addActionListener(this);
        bplot1.addActionListener(this);
        bplot2.addActionListener(this);
        bplot3.addActionListener(this);
    }
    
   public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
    }

    //Addition to reduce flicker new routine
    public void update(Graphics g){		// added to avoid clearing
	    paint(g);
    }
    
    public void drawCanvas(Graphics g){
	Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
        g.setColor(bgcolor);
	g.fillRect(0,0,getSize().width,getSize().height);
        
	g.setColor(Color.blue);
	g.setFont(new Font("Serif",Font.PLAIN,state.font16)); 
	g.drawString("\u03c6",state.s22,state.s177);
	g.setFont(new Font("Serif",Font.PLAIN,state.font14)); 
	g.drawString("= "+slider1.getValue()+"\u00b0",state.s36,state.s177);
	g.setColor(Color.blue);
	g.drawRect(state.s5,state.s132,state.s200+state.s85,state.s58);
	
        g.setColor(Color.red);
	g.drawLine(state.s7,state.s43,getSize().width-state.s7,state.s43);
        
        // CHANGE ==============================================================
        g.setColor(Color.red);
	MaestroG.subscripterSymbol("| E","\u03b8","|",g,state.font12,state.s115,state.s59);
	MaestroG.subscripter2("| E","R","|",g,state.font12,state.s185,state.s59);
        MaestroG.subscripterSymbol("| E","\u03c6","|",g,state.font12,state.s200+state.s55,state.s59);
	g.setColor(Color.blue);
	MaestroG.subscripterSymbol("| H","\u03c6","|",g,state.font12,state.s115,state.s79);
	MaestroG.subscripter2("| H","R","|",g,state.font12,state.s185,state.s79);
        MaestroG.subscripterSymbol("| H","\u03b8","|",g,state.font12,state.s200+state.s55,state.s79);
        
        g.setColor(Color.red);
	MaestroG.subscripter2("| E","x","|",g,state.font12,state.s115,state.s99);
	MaestroG.subscripter2("| E","y","|",g,state.font12,state.s185,state.s99);
	MaestroG.subscripter2("| E","z","|",g,state.font12,state.s200+state.s55,state.s99);
	g.setColor(Color.blue);
	MaestroG.subscripter2("| H","x","|",g,state.font12,state.s115,state.s119);
	MaestroG.subscripter2("| H","y","|",g,state.font12,state.s185,state.s119);
	MaestroG.subscripter2("| H","z","|",g,state.font12,state.s200+state.s55,state.s119);
	//======================================================================
	
        g.setColor(Color.blue); 
	   
	g.setFont(new Font("Serif",Font.PLAIN,state.font14));
	g.drawString("\u03bb",state.s185,state.s152);
	g.setFont(new Font("Serif",Font.PLAIN,state.font14));
    }
    
    public void drawCircle(int x, int y, int radius, Color c, Graphics g){
		g.setColor(c);
		g.drawOval(x-radius,y-radius,2*radius,2*radius);
    }
    
    public void fillCircle(int x, int y, int radius, Color c, Graphics g){
		g.setColor(c);
		g.fillOval(x-radius,y-radius,2*radius,2*radius);
    }
    
    public void reset(){
                pSpher1.setBackground(Color.red);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.red);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                //bSpher1.setLabel(" X ");
                if(state.IsMac){
                    bSpher1.setLabel(" \u2714 ");
                }
                else{
                    bSpher1.setLabel(" \u2713 ");
                }
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                
                pPlot1.setBackground(Color.black);
                pPlot2.setBackground(bgcolor);
                pPlot3.setBackground(bgcolor);
                
                repaint();
    }
    
    public void actionPerformed(ActionEvent evt){
        if(evt.getSource() == bSpher1){
	        pSpher1.setBackground(Color.red);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.red);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                //bSpher1.setLabel(" X ");
                if(state.IsMac){
                    bSpher1.setLabel(" \u2714 ");
                }
                else{
                    bSpher1.setLabel(" \u2713 ");
                }
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bSpher2){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.red);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.red);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                //bSpher2.setLabel(" X ");
                if(state.IsMac){
                    bSpher2.setLabel(" \u2714 ");
                }
                else{
                    bSpher2.setLabel(" \u2713 ");
                }
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
	else if(evt.getSource() == bSpher3){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.red);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.red);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                //bSpher3.setLabel(" X ");
                if(state.IsMac){
                    bSpher3.setLabel(" \u2714 ");
                }
                else{
                    bSpher3.setLabel(" \u2713 ");
                }
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
	else if(evt.getSource() == bSpher4){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.blue);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.blue);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                //bSpher4.setLabel(" X ");
                if(state.IsMac){
                    bSpher4.setLabel(" \u2714 ");
                }
                else{
                    bSpher4.setLabel(" \u2713 ");
                }
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
	else if(evt.getSource() == bSpher5){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.blue);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.blue);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                //bSpher5.setLabel(" X ");
                if(state.IsMac){
                    bSpher5.setLabel(" \u2714 ");
                }
                else{
                    bSpher5.setLabel(" \u2713 ");
                }
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
	else if(evt.getSource() == bSpher6){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.blue);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.blue);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                //bSpher6.setLabel(" X ");
                if(state.IsMac){
                    bSpher6.setLabel(" \u2714 ");
                }
                else{
                    bSpher6.setLabel(" \u2713 ");
                }
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bCart1){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.red);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.red);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                //bCart1.setLabel("X");
                if(state.IsMac){
                    bCart1.setLabel(" \u2714 ");
                }
                else{
                    bCart1.setLabel(" \u2713 ");
                }
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bCart2){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.red);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.red);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                //bCart2.setLabel(" X ");
                if(state.IsMac){
                    bCart2.setLabel(" \u2714 ");
                }
                else{
                    bCart2.setLabel(" \u2713 ");
                }
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bCart3){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.red);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.red);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                //bCart3.setLabel(" X ");
                if(state.IsMac){
                    bCart3.setLabel(" \u2714 ");
                }
                else{
                    bCart3.setLabel(" \u2713 ");
                }
                bCart4.setLabel("");
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bCart4){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.blue);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.blue);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                //bCart4.setLabel(" X ");
                if(state.IsMac){
                    bCart4.setLabel(" \u2714 ");
                }
                else{
                    bCart4.setLabel(" \u2713 ");
                }
                bCart5.setLabel("");
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bCart5){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.blue);
                pCart6.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.blue);
                bCart6.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                //bCart5.setLabel(" X ");
                if(state.IsMac){
                    bCart5.setLabel(" \u2714 ");
                }
                else{
                    bCart5.setLabel(" \u2713 ");
                }
                bCart6.setLabel("");
                repaint();
        }
        
        else if(evt.getSource() == bCart6){
	        pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pSpher4.setBackground(Color.gray);
                pSpher5.setBackground(Color.gray);
                pSpher6.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                pCart6.setBackground(Color.blue);
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bSpher4.setForeground(Color.gray);
                bSpher5.setForeground(Color.gray);
                bSpher6.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                bCart6.setForeground(Color.blue);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bSpher4.setLabel("");
                bSpher5.setLabel("");
                bSpher6.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                //bCart6.setLabel(" X ");
                if(state.IsMac){
                    bCart6.setLabel(" \u2714 ");
                }
                else{
                    bCart6.setLabel(" \u2713 ");
                }
                repaint();
        }
        
        else if(evt.getSource() == bplot1){
                pPlot1.setBackground(Color.black);
                pPlot2.setBackground(bgcolor);
                pPlot3.setBackground(bgcolor);
        }
        else if(evt.getSource() == bplot2){
                pPlot1.setBackground(bgcolor);
                pPlot2.setBackground(Color.black);
                pPlot3.setBackground(bgcolor);
        }
        else if(evt.getSource() == bplot3){
                pPlot1.setBackground(bgcolor);
                pPlot2.setBackground(bgcolor);
                pPlot3.setBackground(Color.black);
        }
        
    }//End of actionPerformed()


    /* THESE ARE NOT USED
    public void adjustmentValueChanged(AdjustmentEvent evt){
	
    }
    public void itemStateChanged(ItemEvent evt){
	
	   if(evt.getSource() == ch1){
	         
	   }
	   if(evt.getSource() == ch2){
	       
	   }  
    }
    */
}


