/*
* hfield.java
* version 1.5
* Milan Petrik 
* 5.9.2000
*/

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.math.*;

/**
*The cFieldCanvas class draws an electric field around the particle, the particle and the animated background.
*@version	1.5
*@author	Milan Petrik
*/

//----------------------------------------------------------------------------------------------
class cFieldCanvas extends Canvas implements Runnable {
//----------------------------------------------------------------------------------------------
	private int ParticleCharge,ParticleX,ParticleY,ParticleShow;
	private double ParticleVelocity;
	private int ForestShow,ForestWidth,ForestHeight,ForestX,ForestY,ForestStep;
	private int CanvasWidth,CanvasHeight;
	private int EFieldType;
	private int BFieldType,BFieldSize,BFieldSizeMax;

	private Thread ForestThread;
	public Image ProtonImage,NeutronImage,ElectronImage,ForestImage;

	//konstanty:
	private double K=2*(1.44E-9f);	//A constant needed to compute the electric field.
	private double E_TO_PIXELS=3e10;
	private double B_TO_PIXELS=3e10/2e29;
	private double L_TO_PIXELS=10e10;
	
	Image offImage;
	Graphics offGraphics;
	
	public cFieldCanvas() {
		int i;
		
		CanvasWidth=450;
		CanvasHeight=450;
		setSize(CanvasWidth,CanvasHeight);
		
		ParticleX=CanvasWidth/2;
		ParticleY=CanvasHeight/2;
		ParticleCharge=1;
		ParticleVelocity=0.0;
		ParticleShow=1;

		ForestShow=1;
		ForestWidth=800;
		ForestHeight=80;
		ForestX=0;
		ForestY=370;
		ForestStep=0;

		EFieldType=1;

		BFieldType=0;
		BFieldSize=4;
		BFieldSizeMax=200;

		start();
		}
		
	public void run() { 
		while(ForestThread!=null) {
		   try {
		      ForestX-=ForestStep;
		      if(ForestX<=-ForestWidth) ForestX=0;
		      ForestThread.sleep(100);
		      } catch (InterruptedException e) {}
		   repaint();
		   }
		}

	void start() {
		ForestThread=new Thread(this);
		ForestThread.setPriority(Thread.MAX_PRIORITY);
		ForestThread.start();
		}
		
	void stop() {
		ForestThread=null;
		}     
		
	public void update(Graphics g) {
		paint(g);
		}  
		
	public void paint(Graphics g) {
		if(offImage==null) {
		   offImage=createImage(CanvasWidth,CanvasHeight);
		   offGraphics=offImage.getGraphics();
		   } 
		   
		DrawBackground();
		DrawBField();
		DrawForest();
		DrawEField();
		DrawParticle();
		
		g.drawImage(offImage,0,0,this);
		}
		
	private void DrawBackground() {
		offGraphics.setColor(new Color((float)0.0,(float)1.0,(float)1.0));
		offGraphics.fillRect(0,0,CanvasWidth,CanvasHeight);
		}
		
	private void DrawForest() {
		if(ForestShow!=0) {
			offGraphics.drawImage(ForestImage,ForestX,ForestY,this);
			offGraphics.drawImage(ForestImage,ForestX+ForestWidth,ForestY,this);
			}
		}
		
	private void DrawParticle() {
		if(ParticleShow==0) return;
		switch(ParticleCharge) {
			case -1:
				offGraphics.drawImage(ElectronImage,ParticleX-6,ParticleY-6,this);
				break;
			case 0:
				offGraphics.drawImage(NeutronImage,ParticleX-6,ParticleY-6,this);
				break;
			case 1:
				offGraphics.drawImage(ProtonImage,ParticleX-6,ParticleY-6,this);
				break;
			}
		}
	
	private void DrawBField() {				

		if((ParticleCharge==0)||(BFieldType<0)) return;
	
		int x,y;
		double BValue,Citatel,Jmenovatel;
		int OvalWidth,HalfOvalWidth,OvalHeight,HalfOvalHeight;
		double m,n,n2,n4,m1,m2,m3;
		double Beta,Gamma,Gamma2,Gamma4,_3Gamma2,_3Gamma4;
		double k1,k2,k3,k4;
		int PixSize,HalfPixSize;
		int HalfWidth,HalfHeight;

		switch(BFieldType) {
			case 0:
				y=BFieldSize;
				n=y/L_TO_PIXELS;
				n2=n*n;
				n4=n2*n2;
		
				Beta=ParticleVelocity;
				Gamma=1/Math.sqrt(1-Beta*Beta);
				Gamma2=Gamma*Gamma;
				Gamma4=Gamma2*Gamma2;
		
				Citatel=Gamma*Beta*n*B_TO_PIXELS*5;

				k1=Gamma2*Gamma4;
				k2=3*Gamma4*n2;
				k3=3*Gamma2*n4;
				k4=n2*n4;

				HalfWidth=CanvasWidth/2;
		
				for(x=5;x<HalfWidth;x+=10) {
					m=x/L_TO_PIXELS;
					m1=m*m;
					m2=m1*m1;
					m3=m1*m2;
					
					Jmenovatel=Math.sqrt(k1*m3 + k2*m2 + k3*m1 + k4);
					BValue=Citatel/Jmenovatel;
				
					if(BValue>1.0) BValue=1.0;
				
					offGraphics.setColor(new Color((float)BValue,(float)(1.0-BValue),(float)(1.0-BValue)));
					offGraphics.drawLine(ParticleX+x,ParticleY+y,ParticleX+x,ParticleY-y);
					offGraphics.drawLine(ParticleX-x,ParticleY+y,ParticleX-x,ParticleY-y);
					}
				break;
			case 1:
				y=BFieldSize;
				n=y/L_TO_PIXELS;
		
				Beta=ParticleVelocity;
				Gamma=1/Math.sqrt(1-Beta*Beta);
		
				Citatel=Gamma*Beta*n*B_TO_PIXELS*5;
		
				k1=Gamma*Gamma*Gamma*Gamma*Gamma*Gamma;
				k2=3*Gamma*Gamma*Gamma*Gamma*n*n;
				k3=3*Gamma*Gamma*n*n*n*n;
				k4=n*n*n*n*n*n;
		
				OvalHeight=2*y;
				HalfOvalHeight=OvalHeight/2;
				for(x=15;x<200;x+=30) {
					m=x/L_TO_PIXELS;
					m1=m*m;
					m2=m1*m1;
					m3=m1*m2;
					
					Jmenovatel=Math.sqrt(k1*m3 + k2*m2 + k3*m1 + k4);
					BValue=Citatel/Jmenovatel;
				
					if(BValue>1.0) BValue=1.0;
				
					offGraphics.setColor(new Color((float)BValue,(float)(1.0-BValue),(float)(1.0-BValue)));
					OvalWidth=OvalHeight/10;
					HalfOvalWidth=OvalWidth/2;
		
					offGraphics.drawOval(ParticleX+x-HalfOvalWidth,ParticleY-HalfOvalHeight,OvalWidth,OvalHeight);
					offGraphics.drawOval(ParticleX-x-HalfOvalWidth,ParticleY-HalfOvalHeight,OvalWidth,OvalHeight);
					}
				break;
			case 2:
				Beta=ParticleVelocity;
				Gamma=1/Math.sqrt(1-Beta*Beta);
				Gamma2=Gamma*Gamma;
				Gamma4=Gamma2*Gamma2;
				_3Gamma2=3*Gamma2;
				_3Gamma4=3*Gamma4;
				k1=Gamma4*Gamma2;
		
				PixSize=BFieldSizeMax-BFieldSize;
				PixSize/=8;
				if(PixSize<1) PixSize=1;
				HalfPixSize=PixSize/2;

				HalfWidth=CanvasWidth/2;
				HalfHeight=CanvasHeight/2;

				for(x=HalfPixSize;x-HalfPixSize<HalfWidth;x+=PixSize) {
					for(y=HalfPixSize;y-HalfPixSize<HalfHeight;y+=PixSize) {
						n=y/L_TO_PIXELS;
						Citatel=Gamma*Beta*n*B_TO_PIXELS;
						n2=n*n;
						n4=n2*n2;
						k2=_3Gamma4*n2;
						k3=_3Gamma2*n4;
						k4=n2*n4;
						
						m=x/L_TO_PIXELS;
						m1=m*m;
						m2=m1*m1;
						m3=m1*m2;
						
						Jmenovatel=Math.sqrt(k1*m3 + k2*m2 + k3*m1 + k4);
						BValue=Citatel/Jmenovatel;
					
						if(BValue>1.0) BValue=1.0;
					
						offGraphics.setColor(new Color((float)BValue,(float)(1.0-BValue),(float)(1.0-BValue)));
		
						offGraphics.fillRect(ParticleX+x-HalfPixSize,ParticleY+y-HalfPixSize,PixSize,PixSize);
						offGraphics.fillRect(ParticleX+x-HalfPixSize,ParticleY-y-HalfPixSize,PixSize,PixSize);
						offGraphics.fillRect(ParticleX-x-HalfPixSize,ParticleY+y-HalfPixSize,PixSize,PixSize);
						offGraphics.fillRect(ParticleX-x-HalfPixSize,ParticleY-y-HalfPixSize,PixSize,PixSize);
						}
					}
				break;
			}
		}

	private void DrawEField() {

		if((ParticleCharge==0)||(EFieldType<0)) return;

		double Beta=ParticleVelocity;	
		double Gamma=Math.sqrt(1-(Beta*Beta));

		double Ex=K/(Gamma*Gamma);
		double Ey=K*Gamma;

		double a=Ey*E_TO_PIXELS;
		double b=Ex*E_TO_PIXELS;
		double xx1,yy1,xx2,yy2,k,alfa;
		int VectorNum=24;
		int VectorCounter;
		double dyy=15;

		offGraphics.setColor(Color.blue);
		switch(EFieldType) {
			case 0: //bez sipek, jenom cary
				offGraphics.setColor(Color.blue);
				for(alfa=0;alfa<3.1415927;alfa+=6.283185307/VectorNum) {
					k=Math.tan(alfa);
					xx1=Math.sqrt((a*a*b*b)/((b*b)+(a*a*k*k)));
					xx2=-xx1;
					yy1=k*xx1;
					yy2=-yy1;
			
					offGraphics.drawLine(ParticleX,ParticleY,ParticleX+(int)xx1,ParticleY+(int)yy1);
					offGraphics.drawLine(ParticleX,ParticleY,ParticleX+(int)xx2,ParticleY+(int)yy2);
					}
				break;   
			case 1: //sipky
				switch(ParticleCharge) {
					case -1:
						offGraphics.setColor(Color.blue);
						VectorNum*=2;
						VectorCounter=0;
						for(alfa=0;alfa<3.1415927;alfa+=6.283185307/VectorNum) {
							k=Math.tan(alfa);
							xx1=Math.sqrt((a*a*b*b)/((b*b)+(a*a*k*k)));
							xx2=-xx1;
							yy1=k*xx1;
							yy2=-yy1;
				
							if((VectorCounter%2)==1) {
								xx1/=3;
								yy1/=3;
								xx2/=3;
								yy2/=3;
								}
							VectorCounter++;   
				
							offGraphics.drawLine(ParticleX,ParticleY,ParticleX+(int)xx1,ParticleY+(int)yy1);
							offGraphics.drawLine(ParticleX,ParticleY,ParticleX+(int)xx2,ParticleY+(int)yy2);
							}
						break;
					case 1:
						offGraphics.setColor(Color.blue);
						for(alfa=0;alfa<3.1415927;alfa+=6.283185307/VectorNum) {
							k=Math.tan(alfa);
							xx1=Math.sqrt((a*a*b*b)/((b*b)+(a*a*k*k)));
							xx2=-xx1;
							yy1=k*xx1;
							yy2=-yy1;
			
							DrawVector(ParticleX,ParticleY,ParticleX+(int)xx1,ParticleY+(int)yy1);
							DrawVector(ParticleX,ParticleY,ParticleX+(int)xx2,ParticleY+(int)yy2);
							}
						break;
					}      
				break;
			case 2:
				break;
			} //end of switch
		}
						
	private void DrawField() {
		if(ParticleCharge!=0) {
			DrawBField();
			DrawEField();
			}
		}

	private void DrawVector(int X1,int Y1,int X2,int Y2) {
		int XX1,YY1,XX2,YY2;
		
		XX1=X2-((X2-X1)/3)-((Y2-Y1)/20);
		YY1=Y2-((Y2-Y1)/3)+((X2-X1)/20);
		XX2=X2-((X2-X1)/3)+((Y2-Y1)/20);
		YY2=Y2-((Y2-Y1)/3)-((X2-X1)/20);
		
		offGraphics.setColor(Color.blue);
		offGraphics.drawLine(X1,Y1,X2,Y2);
		offGraphics.drawLine(X2,Y2,XX1,YY1);
		offGraphics.drawLine(X2,Y2,XX2,YY2);
		}
	
	public void SetParticleShow(int What) {
		if(What!=ParticleShow) ParticleShow=What;
		}
		
	public void SetForestShow(int What) {
		if(What!=ForestShow) ForestShow=What;
		}
		
	public void SetEFieldType(int What) {
		if(What!=EFieldType) EFieldType=What;
		}
		
	public void SetBFieldType(int What) {
		if(What!=BFieldType) BFieldType=What;
		}
		
	public void SetParticleCharge(int What) {
		if(What!=ParticleCharge) ParticleCharge=What;
		}
	  
	public void SetParticleVelocity(double What)
		{
		if(What!=ParticleVelocity) {
		   ParticleVelocity=What;
		   ForestStep=(int)(ParticleVelocity*40);
		   }
		}

	public void SetBFieldSize(int What) {
		if(What!=BFieldSize) BFieldSize=BFieldSizeMax-(BFieldSizeMax*What)/255;
		}

	}

//----------------------------------------------------------------------------------------------
//end of class cFieldCanvas extends Canvas implements Runnable
//----------------------------------------------------------------------------------------------
   
/**
* The cVelocityDisplay class draws the value of Velocity.
*@version	1.5
*@author	Milan Petrik
*/

   
//----------------------------------------------------------------------------------------------   
class cVelocityDisplay extends Canvas {
//----------------------------------------------------------------------------------------------
	private float Value;
	
	cVelocityDisplay(float _Value) {
		setSize(100,10);
		Value=_Value;	
		}
	
	public void paint(Graphics g) {
		g.setColor(Color.black);
		g.drawString("v = "+(""+Value+"000").substring(0,4)+" c",10,14);
		}
		
	public void SetValue(float _Value) {
		if(Value!=_Value) {
			Value=_Value;
			repaint();
			}
		}
		
	public float GetValue() { 
		return Value; 
		}

	}

//----------------------------------------------------------------------------------------------   
//end of class cVelocityDisplay extends Canvas
//----------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------   
class cChargeDisplay extends Canvas {
//----------------------------------------------------------------------------------------------
	
	cChargeDisplay() {
		setSize(105,10);
		}
	
	public void paint(Graphics g) {
		g.setColor(Color.black);
		g.drawString("Particle:",0,14);
		}
		
	}

//----------------------------------------------------------------------------------------------   
//end of class cChargeDisplay extends Canvas
//----------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------   
class cBFieldDisplay extends Canvas {
//----------------------------------------------------------------------------------------------
	
	cBFieldDisplay() {
		setSize(105,10);
		}
	
	public void paint(Graphics g) {
		g.setColor(Color.black);
		g.drawString("Show mg. field:",0,14);
		}
		
	}

//----------------------------------------------------------------------------------------------   
//end of class cBFieldDisplay extends Canvas
//----------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------   
class cEFieldDisplay extends Canvas {
//----------------------------------------------------------------------------------------------
	
	cEFieldDisplay() {
		setSize(105,10);
		}
	
	public void paint(Graphics g) {
		g.setColor(Color.black);
		g.drawString("Show el. field:",0,14);
		}
		
	}

//----------------------------------------------------------------------------------------------   
//end of class cEFieldDisplay extends Canvas
//----------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------   
class cOptionDisplay extends Canvas {
//----------------------------------------------------------------------------------------------
	
	cOptionDisplay() {
		setSize(105,10);
		}
	
	public void paint(Graphics g) {
		g.setColor(Color.black);
		g.drawString("Options:",0,14);
		}
		
	}

//----------------------------------------------------------------------------------------------   
//end of class cOptionDisplay extends Canvas
//----------------------------------------------------------------------------------------------

/**
* The hfield class is an applet, which uses the cFieldCanvas and cVelocityDisplay classes
* to draw and control the drawing of the electric field of the flying particle.
*@version	1.5
*@author	Milan Petrik
*/

//----------------------------------------------------------------------------------------------
public class hfield extends Applet implements ItemListener, AdjustmentListener {
//----------------------------------------------------------------------------------------------
	private cFieldCanvas FieldCanvas=new cFieldCanvas();
	private cVelocityDisplay VelocityDisplay=new cVelocityDisplay(0);

	private cChargeDisplay ChargeDisplay=new cChargeDisplay();
	private cBFieldDisplay BFieldDisplay=new cBFieldDisplay();
	private cEFieldDisplay EFieldDisplay=new cEFieldDisplay();
	private cOptionDisplay OptionDisplay=new cOptionDisplay();

	private Panel VelocityPanel=new Panel();
	private Panel SwitchPanel=new Panel();
	private Panel SwitchChargePanel=new Panel();
	private Panel SwitchEFieldPanel=new Panel();
	private Panel SwitchBFieldPanel=new Panel();
	private Panel SwitchOptionPanel=new Panel();
	private Panel SettingPanel=new Panel();

	private Scrollbar VelocityScroll=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
	private Scrollbar BFieldScroll=new Scrollbar(Scrollbar.VERTICAL,160,1,0,255);

	private CheckboxGroup ChargeCheckbox=new CheckboxGroup();
	private Checkbox ChargeCheckbox1=new Checkbox("electron",ChargeCheckbox,false);
	private Checkbox ChargeCheckbox2=new Checkbox("neutron",ChargeCheckbox,false);
	private Checkbox ChargeCheckbox3=new Checkbox("proton",ChargeCheckbox,true);

	private CheckboxGroup EFieldCheckbox=new CheckboxGroup();
	private Checkbox EFieldCheckbox1=new Checkbox("as lines",EFieldCheckbox,false);
	private Checkbox EFieldCheckbox2=new Checkbox("as vectors",EFieldCheckbox,true);
	private Checkbox EFieldCheckbox3=new Checkbox("don't show",EFieldCheckbox,false);

	private CheckboxGroup BFieldCheckbox=new CheckboxGroup();
	private Checkbox BFieldCheckbox1=new Checkbox("as lines",BFieldCheckbox,false);
	private Checkbox BFieldCheckbox2=new Checkbox("as circles",BFieldCheckbox,true);
	private Checkbox BFieldCheckbox3=new Checkbox("as cloud",BFieldCheckbox,false);
	private Checkbox BFieldCheckbox4=new Checkbox("don't show",BFieldCheckbox,false);

	private Checkbox BackgroundCheckbox=new Checkbox("Show Landscape",true);

	private Checkbox ShowParticleCheckbox=new Checkbox("Show Particle",true);

	public hfield() {
		}

	public void init() {
		FieldCanvas.SetBFieldSize(160);
		FieldCanvas.SetBFieldType(1);

		setLayout(new BorderLayout());

		VelocityPanel.setLayout(new BorderLayout());
		SwitchPanel.setLayout(new FlowLayout());
		SwitchChargePanel.setLayout(new GridLayout(5,1));
		SwitchEFieldPanel.setLayout(new GridLayout(5,1));
		SwitchBFieldPanel.setLayout(new GridLayout(5,1));
		SwitchOptionPanel.setLayout(new GridLayout(5,1));
		SettingPanel.setLayout(new BorderLayout());

		VelocityPanel.add(VelocityScroll,"Center");
		VelocityPanel.add(VelocityDisplay,"West");

		SwitchChargePanel.add(ChargeDisplay);
		SwitchChargePanel.add(ChargeCheckbox1);
		SwitchChargePanel.add(ChargeCheckbox2);
		SwitchChargePanel.add(ChargeCheckbox3);

		SwitchEFieldPanel.add(EFieldDisplay);
		SwitchEFieldPanel.add(EFieldCheckbox1);
		SwitchEFieldPanel.add(EFieldCheckbox2);
		SwitchEFieldPanel.add(EFieldCheckbox3);

		SwitchBFieldPanel.add(BFieldDisplay);
		SwitchBFieldPanel.add(BFieldCheckbox1);
		SwitchBFieldPanel.add(BFieldCheckbox2);
		SwitchBFieldPanel.add(BFieldCheckbox3);
		SwitchBFieldPanel.add(BFieldCheckbox4);

		SwitchOptionPanel.add(OptionDisplay);
		SwitchOptionPanel.add(BackgroundCheckbox);
		SwitchOptionPanel.add(ShowParticleCheckbox);

		SwitchPanel.add(SwitchChargePanel);
		SwitchPanel.add(SwitchBFieldPanel);
		SwitchPanel.add(SwitchEFieldPanel);
		SwitchPanel.add(SwitchOptionPanel);

		SettingPanel.add(VelocityPanel,"South");
		SettingPanel.add(SwitchPanel,"Center");

		add(FieldCanvas,"Center");
		add(SettingPanel,"South");
		add(BFieldScroll,"East");


		VelocityScroll.addAdjustmentListener(this);
		BFieldScroll.addAdjustmentListener(this);

		ChargeCheckbox1.addItemListener(this);
		ChargeCheckbox2.addItemListener(this);
		ChargeCheckbox3.addItemListener(this);
		EFieldCheckbox1.addItemListener(this);
		EFieldCheckbox2.addItemListener(this);
		EFieldCheckbox3.addItemListener(this);
		BFieldCheckbox1.addItemListener(this);
		BFieldCheckbox2.addItemListener(this);
		BFieldCheckbox3.addItemListener(this);
		BFieldCheckbox4.addItemListener(this);
		BackgroundCheckbox.addItemListener(this);
		ShowParticleCheckbox.addItemListener(this);

		//tohleto je prasarna, Prasarna, PRASARNA, P R A S A R N A !!!
		FieldCanvas.ProtonImage=getImage(getDocumentBase(),"protonparticle.gif");
		FieldCanvas.NeutronImage=getImage(getDocumentBase(),"neutronparticle.gif");
		FieldCanvas.ElectronImage=getImage(getDocumentBase(),"electronparticle.gif");
		FieldCanvas.ForestImage=getImage(getDocumentBase(),"les.gif");
		}

	public void start() {
		FieldCanvas.start();
		}
		
	public void run() {
		FieldCanvas.run();
		}
		
	public void update(Graphics g) {
		paint(g);
		}
		
	public void paint(Graphics g) {
		FieldCanvas.paint(g);
		}
		
	public void stop() {
		FieldCanvas.stop();
		}

	 public void itemStateChanged(ItemEvent e) {
		if(ChargeCheckbox1.getState()==true) 	{ FieldCanvas.SetParticleCharge(-1); }
		if(ChargeCheckbox2.getState()==true) 	{ FieldCanvas.SetParticleCharge(0); }
		if(ChargeCheckbox3.getState()==true) 	{ FieldCanvas.SetParticleCharge(1); }
		
		if(EFieldCheckbox1.getState()==true) 	{ FieldCanvas.SetEFieldType(0); }
		if(EFieldCheckbox2.getState()==true) 	{ FieldCanvas.SetEFieldType(1); }
		if(EFieldCheckbox3.getState()==true) 	{ FieldCanvas.SetEFieldType(-1); }

		if(BFieldCheckbox1.getState()==true) 	{ FieldCanvas.SetBFieldType(0); }
		if(BFieldCheckbox2.getState()==true) 	{ FieldCanvas.SetBFieldType(1); }
		if(BFieldCheckbox3.getState()==true) 	{ FieldCanvas.SetBFieldType(2); }
		if(BFieldCheckbox4.getState()==true) 	{ FieldCanvas.SetBFieldType(-1); }

		if(BackgroundCheckbox.getState()==true) 	{ FieldCanvas.SetForestShow(1); }
		if(BackgroundCheckbox.getState()==false) 	{ FieldCanvas.SetForestShow(0); }

		if(ShowParticleCheckbox.getState()==true) 	{ FieldCanvas.SetParticleShow(1); }
		if(ShowParticleCheckbox.getState()==false) 	{ FieldCanvas.SetParticleShow(0); }
		}

	public void adjustmentValueChanged(AdjustmentEvent e) {
		int a=VelocityScroll.getValue();	
		int b=BFieldScroll.getValue();

		VelocityDisplay.SetValue((float)a/255);
		FieldCanvas.SetParticleVelocity((float)a/255);
		//MgDisplay.SetValue((float)b/255);
		FieldCanvas.SetBFieldSize(b);
		}	

	public static void main (String args[]) {
		hfield hf=new hfield();
		hf.init();
		Frame f=new Frame("Heavisides field");
		f.add(hf,"Center");
		f.setSize(450,540);
		f.setVisible(true);
		hf.start();
		}

	}

