I am sorry that I was too busy in the last two weeks so that I was not able to help you with the coding.
Finally, I tried to modify from my previous version and the result (for two magnets) is the following :

/htdocs/ntnujava/ejsuser/2/users/ntnu/fkh/Magnrtic2BarFieldFKH2_pkg/Magnrtic2BarFieldFKH2.propertiesFull screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
Download EJS jar file(1032.6kB):double click downloaded file to run it. (18 times by 10 users) , Download EJS source (11 times by 8 users) View EJS source