
// ****************************************************************************************************
//                                          cp3D.bupdate button code
// ****************************************************************************************************


	    System.out.println("YAY THE CRAZY BUTTON");
	    
	    try{
		if(Double.valueOf(cp3D.text3.getText()).doubleValue()>=0.0 && 
		   Double.valueOf(cp3D.text3.getText()).doubleValue()<=state.distance_maximum){
		    state.point_distance=Double.valueOf(cp3D.text3.getText()).doubleValue();
		    state.distance = state.point_distance * state.wavelength;
		}
		else if(Double.valueOf(cp3D.text3.getText()).doubleValue()>state.distance_maximum){
		    state.point_distance=state.distance_maximum;
		    state.distance = state.point_distance * state.wavelength;
		    cp3D.text3.setText(""+state.point_distance);
		}
		else{
		    state.point_distance=0.0;
		    state.distance=0.0;
		    cp3D.text3.setText(""+state.point_distance);
		}
	    } 
	    catch(NumberFormatException e){
		  state.point_distance = 0.0;
	    }
	    
	    state.phi_angle = cp3D.slider1.getValue();
	    inputpanel2.slider3.setValue((int)(inputpanel2.ScrollMax2*(state.phi_angle-state.phi_minimum)/
					    (state.phi_maximum-state.phi_minimum)));
	    inputpanel2.slider30.setValue(0);
	    inputpanel2.text2.setText(""+MaestroA.rounder(state.phi_angle,7));
	    
		    state.ignition();
		    //state.scan3Dfield();  // ---> THIS WAS THE ORIGINAL CALL
		    //Scan3DField calculate = new Scan3DField(state);
		    //calculate.start();

		    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
		    // Start a thread, so that GUI appears to be responsive (Cheerpj / javascript)
		    Update3D calculate = new Update3D();
		    calculate.start();
		    

		    /* THIS IS IDENTICAL to update3D() function, so just comment out
		    
		    rwccf.setYRangeMax(state.EfieldMax);
		    rwccf.setYRangeMin(0.0);
		    rwccf.plotZeroLine(false);
		    rwccf.plotRefPoint(false);
		    rwccf.setPolar(state.IsPolar);
		    rwccf.setPhiAngle((int)state.phi_angle);
		    rwccf.setType(1);
		    rwccf.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    rwccg.setYRangeMax(state.EfieldphiMax);
		    rwccg.setYRangeMin(0.0);
		    rwccg.plotZeroLine(false);
		    rwccg.plotRefPoint(false);
		    rwccg.setPolar(state.IsPolar);
		    rwccg.setPhiAngle((int)state.phi_angle);
		    rwccg.setType(1);
		    rwccg.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwcch.setYRangeMax(state.EfieldRadMax);
		    rwcch.setYRangeMin(0.0);
		    rwcch.plotZeroLine(false);
		    rwcch.plotRefPoint(false);
		    rwcch.setPolar(state.IsPolar);
		    rwcch.setPhiAngle((int)state.phi_angle);
		    rwcch.setType(2);
		    rwcch.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccj.setYRangeMax(state.EfieldphiRadMax);
		    rwccj.setYRangeMin(0.0);
		    rwccj.plotZeroLine(false);
		    rwccj.plotRefPoint(false);
		    rwccj.setPolar(state.IsPolar);
		    rwccj.setPhiAngle((int)state.phi_angle);
		    rwccj.setType(2);
		    rwccj.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwcch2.setYRangeMax(state.EfieldPhigenMax);
		    rwcch2.setYRangeMin(0.0);
		    rwcch2.plotZeroLine(false);
		    rwcch2.plotRefPoint(false);
		    rwcch2.setPolar(state.IsPolar);
		    rwcch2.setPhiAngle((int)state.phi_angle);
		    rwcch2.setType(10);
		    rwcch2.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		   		    
		    rwccj2.setYRangeMax(state.EfieldphiPhiMax);
		    rwccj2.setYRangeMin(0.0);
		    rwccj2.plotZeroLine(false);
		    rwccj2.plotRefPoint(false);
		    rwccj2.setPolar(state.IsPolar);
		    rwccj2.setPhiAngle((int)state.phi_angle);
		    rwccj2.setType(10);
		    rwccj2.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwcck.setYRangeMax(state.EfieldCartxMax);
		    rwcck.setYRangeMin(0.0);
		    rwcck.plotZeroLine(false);
		    rwcck.plotRefPoint(false);
		    rwcck.setPolar(state.IsPolar);
		    rwcck.setPhiAngle((int)state.phi_angle);
		    rwcck.setType(3);
		    rwcck.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccl.setYRangeMax(state.EfieldCartyMax);
		    rwccl.setYRangeMin(0.0);
		    rwccl.plotZeroLine(false);
		    rwccl.plotRefPoint(false);
		    rwccl.setPolar(state.IsPolar);
		    rwccl.setPhiAngle((int)state.phi_angle);
		    rwccl.setType(4);
		    rwccl.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccm.setYRangeMax(state.EfieldCartzMax);
		    rwccm.setYRangeMin(0.0);
		    rwccm.plotZeroLine(false);
		    rwccm.plotRefPoint(false);
		    rwccm.setPolar(state.IsPolar);
		    rwccm.setPhiAngle((int)state.phi_angle);
		    rwccm.setType(5);
		    rwccm.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccn.setYRangeMax(state.EfieldCart2xMax);
		    rwccn.setYRangeMin(0.0);
		    rwccn.plotZeroLine(false);
		    rwccn.plotRefPoint(false);
		    rwccn.setPolar(state.IsPolar);
		    rwccn.setPhiAngle((int)state.phi_angle);
		    rwccn.setType(3);
		    rwccn.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwcco.setYRangeMax(state.EfieldCart2yMax);
		    rwcco.setYRangeMin(0.0);
		    rwcco.plotZeroLine(false);
		    rwcco.plotRefPoint(false);
		    rwcco.setPolar(state.IsPolar);
		    rwcco.setPhiAngle((int)state.phi_angle);
		    rwcco.setType(4);
		    rwcco.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwccp.setYRangeMax(state.EfieldCart2zMax);
		    rwccp.setYRangeMin(0.0);
		    rwccp.plotZeroLine(false);
		    rwccp.plotRefPoint(false);
		    rwccp.setPolar(state.IsPolar);
		    rwccp.setPhiAngle((int)state.phi_angle);
		    rwccp.setType(5);
		    rwccp.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwccr.setYRangeMax(state.HfieldMax);
		    rwccr.setYRangeMin(0.0);
		    rwccr.plotZeroLine(false);
		    rwccr.plotRefPoint(false);
		    rwccr.setPolar(state.IsPolar);
		    rwccr.setPhiAngle((int)state.phi_angle);
		    rwccr.setType(6);
		    rwccr.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccr2.setYRangeMax(state.HfieldRadMax);
		    rwccr2.setYRangeMin(0.0);
		    rwccr2.plotZeroLine(false);
		    rwccr2.plotRefPoint(false);
		    rwccr2.setPolar(state.IsPolar);
		    rwccr2.setPhiAngle((int)state.phi_angle);
		    rwccr2.setType(11);
		    rwccr2.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccr3.setYRangeMax(state.HfieldThetaMax);
		    rwccr3.setYRangeMin(0.0);
		    rwccr3.plotZeroLine(false);
		    rwccr3.plotRefPoint(false);
		    rwccr3.setPolar(state.IsPolar);
		    rwccr3.setPhiAngle((int)state.phi_angle);
		    rwccr3.setType(12);
		    rwccr3.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccs.setYRangeMax(state.HfieldphiMax);
		    rwccs.setYRangeMin(0.0);
		    rwccs.plotZeroLine(false);
		    rwccs.plotRefPoint(false);
		    rwccs.setPolar(state.IsPolar);
		    rwccs.setPhiAngle((int)state.phi_angle);
		    rwccs.setType(6);
		    rwccs.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwccs2.setYRangeMax(state.HfieldphiRadMax);
		    rwccs2.setYRangeMin(0.0);
		    rwccs2.plotZeroLine(false);
		    rwccs2.plotRefPoint(false);
		    rwccs2.setPolar(state.IsPolar);
		    rwccs2.setPhiAngle((int)state.phi_angle);
		    rwccs2.setType(11);
		    rwccs2.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwccs3.setYRangeMax(state.HfieldphiThetaMax);
		    rwccs3.setYRangeMin(0.0);
		    rwccs3.plotZeroLine(false);
		    rwccs3.plotRefPoint(false);
		    rwccs3.setPolar(state.IsPolar);
		    rwccs3.setPhiAngle((int)state.phi_angle);
		    rwccs3.setType(12);
		    rwccs3.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    
		    //-------------------------------------------  new: H cartesian components
		    rwcct.setYRangeMax(state.HfieldCartxMax);
		    rwcct.setYRangeMin(0.0);
		    rwcct.plotZeroLine(false);
		    rwcct.plotRefPoint(false);
		    rwcct.setPolar(state.IsPolar);
		    rwcct.setPhiAngle((int)state.phi_angle);
		    rwcct.setType(7);
		    rwcct.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccu.setYRangeMax(state.HfieldCart2xMax);
		    rwccu.setYRangeMin(0.0);
		    rwccu.plotZeroLine(false);
		    rwccu.plotRefPoint(false);
		    rwccu.setPolar(state.IsPolar);
		    rwccu.setPhiAngle((int)state.phi_angle);
		    rwccu.setType(7);
		    rwccu.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwccv.setYRangeMax(state.HfieldCartyMax);
		    rwccv.setYRangeMin(0.0);
		    rwccv.plotZeroLine(false);
		    rwccv.plotRefPoint(false);
		    rwccv.setPolar(state.IsPolar);
		    rwccv.setPhiAngle((int)state.phi_angle);
		    rwccv.setType(8);
		    rwccv.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccw.setYRangeMax(state.HfieldCart2yMax);
		    rwccw.setYRangeMin(0.0);
		    rwccw.plotZeroLine(false);
		    rwccw.plotRefPoint(false);
		    rwccw.setPolar(state.IsPolar);
		    rwccw.setPhiAngle((int)state.phi_angle);
		    rwccw.setType(8);
		    rwccw.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    rwccx.setYRangeMax(state.HfieldCartzMax);
		    rwccx.setYRangeMin(0.0);
		    rwccx.plotZeroLine(false);
		    rwccx.plotRefPoint(false);
		    rwccx.setPolar(state.IsPolar);
		    rwccx.setPhiAngle((int)state.phi_angle);
		    rwccx.setType(9);
		    rwccx.setLabels("\u03c6 = "+((int)state.phi_angle)+"\u00ba plane","V/m","\u03b8  [degrees]");
		    
		    rwccy.setYRangeMax(state.HfieldCart2zMax);
		    rwccy.setYRangeMin(0.0);
		    rwccy.plotZeroLine(false);
		    rwccy.plotRefPoint(false);
		    rwccy.setPolar(state.IsPolar);
		    rwccy.setPhiAngle((int)state.phi_angle);
		    rwccy.setType(9);
		    rwccy.setLabels("\u03b8 = 90.0\u00ba plane","V/m","\u03c6  [degrees]");
		    
		    //---------------------------------------------------------
		    
		    state.Is_theta = true;
		    state.Is_radius = false;

		    rwccf.plot(state.x_polar,state.ethetaM);
		    rwcch.plot(state.x_polar,state.eradM);
		    rwcch2.plot(state.x_polar,state.ephigenM);
		    rwccg.plot(state.x_polar,state.ephiM);
		    rwccj.plot(state.x_polar,state.ephiradM);
		    rwccj2.plot(state.x_polar,state.ephiphiM);
		    rwccr.plot(state.x_polar,state.hphigenM);
		    rwccs.plot(state.x_polar,state.hphiM);
		    
		    rwcck.plot(state.x_polar,state.ex);
		    rwccl.plot(state.x_polar,state.ey);
		    rwccm.plot(state.x_polar,state.ez);
		    rwccn.plot(state.x_polar,state.ephix);
		    rwcco.plot(state.x_polar,state.ephiy);
		    rwccp.plot(state.x_polar,state.ephiz);
		    rwcct.plot(state.x_polar,state.hx);
		    rwccu.plot(state.x_polar,state.hphix);
		    rwccv.plot(state.x_polar,state.hy);
		    rwccw.plot(state.x_polar,state.hphiy);
		    rwccx.plot(state.x_polar,state.hz);
		    rwccy.plot(state.x_polar,state.hphiz);
		    
		    rwccf.ignition();
		    rwccf.repaint();
		    rwccg.ignition();
		    rwccg.repaint();
		    rwcch.ignition();
		    rwcch.repaint();
		    rwccj.ignition();
		    rwccj.repaint();
		    rwcch2.ignition();
		    rwcch2.repaint();
		    rwccj2.ignition();
		    rwccj2.repaint();
		    rwcck.ignition();
		    rwcck.repaint();
		    rwccl.ignition();
		    rwccl.repaint();
		    rwccm.ignition();
		    rwccm.repaint();
		    rwccn.ignition();
		    rwccn.repaint();
		    rwcco.ignition();
		    rwcco.repaint();
		    rwccp.ignition();
		    rwccp.repaint();
		    rwccr.ignition();
		    rwccr.repaint();
		    rwccs.ignition();
		    rwccs.repaint();
		    
		    rwccr2.ignition();
		    rwccr2.repaint();
		    rwccs2.ignition();
		    rwccs2.repaint();
		    
		    rwccr3.ignition();
		    rwccr3.repaint();
		    rwccs3.ignition();
		    rwccs3.repaint();
		    
		    rwcct.ignition();
		    rwcct.repaint();
		    rwccu.ignition();
		    rwccu.repaint();
		    rwccv.ignition();
		    rwccv.repaint();
		    rwccw.ignition();
		    rwccw.repaint();
		    rwccx.ignition();
		    rwccx.repaint();
		    rwccy.ignition();
		    rwccy.repaint();
		    
		    rwc.setField(state.IsEfield);
		    rwc.set3D(true);
		    rwc.repaint();
		    
		    rwc2.setFrequency(state.frequency);
		    rwc2.setEpsilon(state.epsilon_r);
		    rwc2.setWavelength(state.wavelength);
		    rwc2.setTheta(state.theta_angle);
		    rwc2.setPhi(state.phi_angle);
		    rwc2.setDistance(state.point_distance);
    
		    rwc2.repaint();
		    
		    outputpanel2.rwocC.repaint();
		    outputpanel2.rwocD.repaint();
		    outputpanel2.tcanvas.repaint();
		    outputpanel3.rwocE.repaint();
		    outputpanel3.rwocF.repaint();
		    outputpanel3.tcanvas2.repaint();
		    outputpanel4.rwocG.repaint();
		    outputpanel4.rwocH.repaint();
		    outputpanel4.tcanvas3.repaint();
		    outputpanel5.rwocI.repaint();
		    outputpanel5.rwocJ.repaint();
		    outputpanel5.tcanvas4.repaint();
		    
		    outputpanel4b.rwocGb.repaint();
		    outputpanel4b.rwocHb.repaint();
		    outputpanel4b.tcanvas3b.repaint();
		    outputpanel5b.rwocIb.repaint();
		    outputpanel5b.rwocJb.repaint();
		    outputpanel5b.tcanvas4b.repaint();
		    
		    outputpanel6.rwocK.repaint();
		    outputpanel6.rwocL.repaint();
		    outputpanel6.tcanvas5.repaint();
		    outputpanel7.rwocM.repaint();
		    outputpanel7.rwocN.repaint();
		    outputpanel7.tcanvas6.repaint();
		    outputpanel8.rwocO.repaint();
		    outputpanel8.rwocP.repaint();
		    outputpanel8.tcanvas7.repaint();
		    outputpanel9.rwocQ.repaint();
		    outputpanel9.rwocR.repaint();
		    outputpanel9.tcanvas8.repaint();
		    outputpanel10.rwocS.repaint();
		    outputpanel10.rwocT.repaint();
		    outputpanel10.tcanvas9.repaint();
		    outputpanel11.rwocU.repaint();
		    outputpanel11.rwocV.repaint();
		    outputpanel11.tcanvas10.repaint();
		    outputpanel13.rwoc6P.repaint();
		    outputpanel13.rwoc7P.repaint();
		    outputpanel13.tcanvas12.repaint();
		    outputpanel14.rwoc8P.repaint();
		    outputpanel14.rwoc9P.repaint();
		    outputpanel14.tcanvas13.repaint();
		    
		    outputpanel13b.rwoc6Pb.repaint();
		    outputpanel13b.rwoc7Pb.repaint();
		    outputpanel13b.tcanvas12b.repaint();
		    outputpanel14b.rwoc8Pb.repaint();
		    outputpanel14b.rwoc9Pb.repaint();
		    outputpanel14b.tcanvas13b.repaint();
		    
		    outputpanel13c.rwoc6Pc.repaint();
		    outputpanel13c.rwoc7Pc.repaint();
		    outputpanel13c.tcanvas12c.repaint();
		    outputpanel14c.rwoc8Pc.repaint();
		    outputpanel14c.rwoc9Pc.repaint();
		    outputpanel14c.tcanvas13c.repaint();
		    
		    outputpanel15.rwoc10P.repaint();
		    outputpanel15.rwoc11P.repaint();
		    outputpanel15.tcanvas14.repaint();
		    outputpanel16.rwoc12P.repaint();
		    outputpanel16.rwoc13P.repaint();
		    outputpanel16.tcanvas15.repaint();
		    outputpanel17.rwoc14P.repaint();
		    outputpanel17.rwoc15P.repaint();
		    outputpanel17.tcanvas16.repaint();
		    outputpanel18.rwoc16P.repaint();
		    outputpanel18.rwoc17P.repaint();
		    outputpanel18.tcanvas17.repaint();
		    outputpanel19.rwoc18P.repaint();
		    outputpanel19.rwoc19P.repaint();
		    outputpanel19.tcanvas18.repaint();
		    outputpanel20.rwoc20P.repaint();
		    outputpanel20.rwoc21P.repaint();
		    outputpanel20.tcanvas19.repaint();
		    
		    inputpanel2.text4.setText(""+state.point_distance);
		    inputpanel2.slider2.setValue((int)((state.point_distance-state.distance_minimum)*inputpanel2.ScrollMax/(state.distance_maximum-state.distance_minimum)));
		    inputpanel2.repaint();
		    */
